Hi, I am coding a simulation and have a couple of possibilities for structuring the data. I’d like to sort out which is likely to be the most efficient. I’ve written toy examples for some of the options, but the results have not been super informative.
The model accrues ~100k agents over time, each of which has some mutable and some immutable characteristics. The latter are updated several thousand times during a run. The final number of agents is known prior to run. I don’t have a ton of experience with Julia, so I am wondering if there are options other than those mentioned below that I should be aware of for structuring the data, or details related to some of these approaches that would be good to know about for performance.
Some of the possible strategies, which could be implemented on their own or in combination:
- Make Agent a mutable struct, and add a const designator to those values that don’t need to change
- Make Agent an immutable struct and use @reset to change those values that need to
- Make an immutable struct for the unchanging values, a mutable one for the others, and link/filter them with a unique id
- Start the run with an empty array of agents, and push agents into it as they enter the model
- Start the run with a full array of agents and designate some as active as they enter the model
- Put the whole thing in a dataframe or some other kind of structure.
- Make an immutable struct for the changing values, and simply add a new element/record to the struct array each time an agent’s characteristics change
Thanks for any knowledge you can share!