forked from 1b-agent/opencadstudio-upstream
perf: cache SortEntitiesTable scan (option E)
Replace the O(objects) linear scan inside wires_for_block() with a sort_cache keyed by geometry_epoch. On a cache miss the index is built once by scanning all document objects; subsequent calls within the same epoch do an O(1) HashMap lookup (block_handle → entity→sort map). Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
This commit is contained in:
1 parent
d1ecaf4695
commit
9c8c9a4060
2 files changed
+49
-23
No files matched your search
+9
-6
@@ -109,13 +109,16 @@ bounding boxes for all entity types.
|
||||
|
||||
---
|
||||
|
||||
## Option E — SortEntitiesTable Scan Cache
|
||||
## Option E — SortEntitiesTable Scan Cache ✅ Implemented
|
||||
|
||||
**Status:** Planned
|
||||
**Status:** Done
|
||||
|
||||
Cache the result of the `SortEntitiesTable` lookup that currently performs a linear scan over all
|
||||
objects on every `wires_for_block()` call.
|
||||
Added `sort_cache: RefCell<Option<(u64, HashMap<Handle, HashMap<u64, u64>>)>>` to `Scene`.
|
||||
|
||||
**Impact:** Minor. Removes one O(objects) scan per frame. Low priority compared to A–D.
|
||||
On the first call to `wires_for_block()` after a geometry change, the cache scans all
|
||||
`document.objects` once and builds an index: `block_handle → (entity_handle.value() →
|
||||
sort_handle.value())`. Subsequent calls within the same epoch do an O(1) HashMap lookup
|
||||
instead of the previous O(objects) `find_map` scan.
|
||||
|
||||
**Difficulty:** Easy.
|
||||
The cache is keyed by `geometry_epoch` and invalidated automatically alongside the wire
|
||||
and GPU caches whenever geometry changes.
|
||||
Reference in new issue
Block a user