Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy constructor of Species is too slow #234

Open
kaizu opened this issue Feb 15, 2018 · 1 comment
Open

Copy constructor of Species is too slow #234

kaizu opened this issue Feb 15, 2018 · 1 comment

Comments

@kaizu
Copy link
Member

kaizu commented Feb 15, 2018

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.

@ToruNiina
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants