Add manual dirty flag optimization to AgentDataSet#3346
Conversation
|
Performance benchmarks:
|
|
The current implementation in this PR forces the user to always handle the dirty flag. This is, in my view, less than ideal. Rather it should be an opt in behavior. So, probably in the |
|
I’ve updated the implementation so the dirty-flag caching is now opt-in via a keyword argument in |
quaquel
left a comment
There was a problem hiding this comment.
one minor comment left, but this looks almost ready to go.
|
I’ve made the suggested changes, thanks for the review. Let me know if anything else should be adjusted. |
quaquel
left a comment
There was a problem hiding this comment.
It looks good to me. I still want to test a few things locally before merging. Hope to get to this somewhere in the coming days.
| def track_agents( | ||
| self, | ||
| agents: AbstractAgentSet, | ||
| name: str, | ||
| fields: str | list[str] | None = None, | ||
| ) -> AgentDataSet: | ||
| """Track the specified fields for the agents in the AgentSet.""" |
There was a problem hiding this comment.
please update this as well to match the new signature of AgentDataSet
There was a problem hiding this comment.
I've updated the track_agents signature to match AgentDataSet
Summary
Adds a manual dirty-flag optimization to
AgentDataSetto avoid repeated data extraction within the same simulation instant. This is implemented as a pull-based caching mechanism that recomputes only when explicitly invalidated.Adds the dirty flag function mentioned in #3341
Motive
AgentDataSet.datacurrently recomputes the snapshot on every access. When datasets are reused within the same simulation instant, this results in redundant extraction work. This change introduces a manualset_dirty_flag()method so model code can explicitly mark the dataset as stale when needed.Implementation
Added two internal attributes to
AgentDataSet,_is_dirtyand_cacheand modified.datato recompute only if_is_dirtyis True or_cacheis None, otherwise return cached snapshotAdded a function,
which marks the dataset as dirty for the next access.
Usage Examples
Additional Notes
.dataaccess now returns the same list object until invalidated.