Copy constructor of Species is too slow
This would be due to attributes. https://github.com/ecell/ecell4/blob/master/ecell4/core/Species.hpp#L52-L61
Species should be lightweight and handy.
PR #232 reduces the cost of copy-constructor. I have some idea to solve the problem without drastic design change,
- use
boost::container::flat_map. this makes memory requirement smaller than that ofstd::(tr1::)unordered_map. - use
boost::container::small_vector<std::pair<string, attribute_type>, N>. This removes heap allocation when the number of attributes is less thanN. If you need more attributes, it will allocate enough memory. - use
boost::array<std::pair<string, attribute_type>, N>andboost::optional<(unordered_)map<string, attribute_type>>. This has mostly the same effect as 2.
If ecell4 can use the latest version of Boost (1.66.0), boost::container::small_vector can be used as a backend of boost::container::flat_map. I think it is the best way because it conserves the interface and remove small heap allocation simultaneously.
We need no link to use Boost.container. it is header-only library. Here is a link to the release notes of Boost.container. http://www.boost.org/doc/libs/1_66_0/doc/html/container/release_notes.html#container.release_notes.release_notes_boost_1_49_00