Skip to content

Ensure minimal number of GraphArrayView invalidation calls#300

Merged
JoOkuma merged 9 commits into
royerlab:mainfrom
cmalinmayor:targeted-updates
Jun 18, 2026
Merged

Ensure minimal number of GraphArrayView invalidation calls#300
JoOkuma merged 9 commits into
royerlab:mainfrom
cmalinmayor:targeted-updates

Conversation

@cmalinmayor

@cmalinmayor cmalinmayor commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Currently, GraphArrayView invalidates the old and new bboxes in the cache any time any node attribute is updated, including totally unrelated ones.

Also, it appears that SQLGraph emits the signal that triggers this twice:

for node_id in updated_node_ids:
self.node_updated.emit(node_id, old_attrs_by_id[node_id], new_attrs_by_id[node_id])
and
for node_id in updated_node_ids:
self.node_updated.emit(node_id, old_attrs_by_id[node_id], new_attrs_by_id[node_id])

Every cache invalidation is expensive, and re-invaliding the same area multiple times resets any progress already made in loading.

This PR ensures the following behavior for all graph backends:

  • If the spatial bbox and attr_key are unchanged, do not invalidate the cache
  • If the spatial box is unchanged but the attr_key changes, invalidate the cache once
  • If the spatial bbox is changed, invalidate the cache twice (old and new bboxes)

@JoOkuma JoOkuma marked this pull request as ready for review June 15, 2026 18:50
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.89%. Comparing base (13f9ba8) to head (9fe0098).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #300      +/-   ##
==========================================
+ Coverage   87.81%   87.89%   +0.07%     
==========================================
  Files          57       57              
  Lines        4998     4997       -1     
  Branches      877      876       -1     
==========================================
+ Hits         4389     4392       +3     
+ Misses        384      382       -2     
+ Partials      225      223       -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

JoOkuma added 2 commits June 16, 2026 06:38
Make _invalidate_bbox accept parallel sequences of times and bboxes so
the node event handlers issue a single call instead of one per node.
The cache's invalidate() is left untouched: invalidation only flips
ready flags and zeroes buffer regions, and recomputation is already
coalesced in NDChunkCache.get(), so grouping there buys nothing.

Read the bbox via dict.get() and treat a missing bbox as an unknown
location, invalidating the whole volume for that time. This keeps it
distinct from a bbox that lies outside the array volume (which
invalidates nothing) and prevents a KeyError from the cache observer
when add_node/bulk_add_nodes emit attrs without a bbox key.
@JoOkuma

JoOkuma commented Jun 16, 2026

Copy link
Copy Markdown
Member

@cmalinmayor, I merged with main and made it work with a list of items.

What about if the masks are changed?
Shouldn't we validate this as well on updates?

JoOkuma added 2 commits June 16, 2026 10:02
The node-updated handler only invalidated when the displayed attribute
value or the bbox changed, so swapping a node's mask while keeping the
same bbox left a stale rendering in the cache. Add a mask-content check
(_mask_changed) so an unchanged-bbox mask update still invalidates the
region, while a re-supplied identical mask invalidates nothing.

@JoOkuma JoOkuma left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cmalinmayor LGTM, I made quite a few changes.
With the recent changes, it takes a list of events.
Could you take a look to see if you agree with everything, or if there's anything else to add?

Comment thread src/tracksdata/array/_test/test_graph_array.py Outdated
@JoOkuma

JoOkuma commented Jun 18, 2026

Copy link
Copy Markdown
Member

@cmalinmayor, I'm addressed your comment. I'm going to merge this. If I missed anything, we can open another PR.
Thanks for starting this.

@JoOkuma JoOkuma merged commit 65ef513 into royerlab:main Jun 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants