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

Keep herbivore objects in contiguous memory space #19

Open
6 tasks
wtraylor opened this issue Mar 31, 2020 · 0 comments
Open
6 tasks

Keep herbivore objects in contiguous memory space #19

wtraylor opened this issue Mar 31, 2020 · 0 comments
Labels
performance Performance improvement refactoring Restructuring or rewriting of code

Comments

@wtraylor
Copy link
Owner

The goal is to reduce access time to herbivore objects when iterating over them. Coherent memory chunks are loaded into L2 and L1 cache, and so the following herbivore object is likely to be accessed a lot faster.

  1. Remove reference to HFT from the CreateHerbivore* classes, but instead store it in the population class and pass it to the creator class as a function parameter.
    • This way the herbivore objects of all HFTs lie together in memory. This makes sense because total forage demands in one habitat are always calculated across all HFTs.
  2. Make CreateHerbivoreCohort and CreateHerbivorePopulation member variables of WorldConstructor.
    • This means that the herbivore objects across all habitats are stored in contiguous memory.
    • Currently that is not necessary because there is no interaction between habitats. In the future this might change, though, if we implement migration across habitats and grid cells.
  3. In WorldConstructor::create_population() pass only the reference to the respective CreateHerbivore* object.
  4. Let CreateHerbivoreCohort and CreateHerbivorePopulation return pointers, not new objects. For this step, just keep all herbivore objects in a member variable: avector of std::unique_ptr objects.
  5. Keep all herbivore objects in big contiguous memory blocks.
    • Each CreateHerbivore* object has a set of memory blocks (std::list< std::vector<HerbivoreCohort> >).
    • Each block gets reserved for a certain capacity, and never gets reallocated.
    • When one block is full, a new block is allocated.
    • A new herbivore object is created with emplace_back() in the herbivore object vector of the current block.
    • An herbivore object can be marked as dead, but remains in memory.
  6. Replace dead herbivore objects.
    • When a new herbivore object is to be created, the blocks are searched for existing dead herbivores first. If one is found, it will be overwritten.
@wtraylor wtraylor added performance Performance improvement refactoring Restructuring or rewriting of code labels Mar 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Performance improvement refactoring Restructuring or rewriting of code
Projects
None yet
Development

No branches or pull requests

1 participant