ecell4_base icon indicating copy to clipboard operation
ecell4_base copied to clipboard

Copy constructor of Species is too slow

Open kaizu opened this issue 7 years ago • 1 comments

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.

kaizu avatar Feb 15 '18 07:02 kaizu

PR #232 reduces the cost of copy-constructor. I have some idea to solve the problem without drastic design change,

  1. use boost::container::flat_map. this makes memory requirement smaller than that of std::(tr1::)unordered_map.
  2. use boost::container::small_vector<std::pair<string, attribute_type>, N>. This removes heap allocation when the number of attributes is less than N. If you need more attributes, it will allocate enough memory.
  3. use boost::array<std::pair<string, attribute_type>, N> and boost::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

ToruNiina avatar Feb 16 '18 08:02 ToruNiina