forked from 1b-agent/opencadstudio-upstream
perf: stop rescanning every entity to fill the selection-filter menu
Pan and even plain cursor movement over the canvas ran at ~8 fps on a large drawing. Nothing rendered was responsible: the GPU idled at 0-8%, encoding no scene at all changed nothing, and vertices, pixels and draw calls could each be cut without moving the number. `view` was the frame -- 110 ms of it against 3-6 ms on a small drawing -- and inside `view` it was the status bar. The status bar builds the selection-filter menu, which asks for the distinct entity type names in the layout. That call cloned the layout's entire handle list (1 166 357 handles, ~9 MB), then did a map lookup, a String allocation and a BTreeSet insert for each one. About 107 ms of a 110 ms frame, to produce roughly twenty names, for a menu that is only visible when opened. Cache the result against geometry_epoch and the layout block, since it only changes when entities are added or removed, and make the scan itself borrow the handle list rather than clone it and collect &str, allocating only for the names it returns. The immediate-mode UI rebuilds every widget on every mouse move, which is fine as long as nothing in that path is O(document). This was. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
886d5777d8
commit
f1efc73cbe
4 files changed
+51
-12
No files matched your search
@@ -1715,6 +1715,11 @@ pub struct Scene {
|
||||
/// Reverse map: entity_handle → block_record_handle, built from entity_handles lists.
|
||||
/// Keyed by geometry_epoch. Eliminates the O(B) fallback scan in belongs_to_visible_block.
|
||||
entity_block_map_cache: RefCell<Option<(u64, HashMap<Handle, Handle>)>>,
|
||||
/// Distinct entity type names present in a layout, keyed by
|
||||
/// (geometry_epoch, layout block). The status bar asks for this on every
|
||||
/// frame to populate the selection-filter menu, but the answer only
|
||||
/// changes when entities are added or removed.
|
||||
layout_type_names_cache: RefCell<Option<(u64, Handle, std::sync::Arc<Vec<String>>)>>,
|
||||
/// Reverse dependencies from layer/style/block definitions to the top-level
|
||||
/// entities whose resident wire runs actually change. Kept independent from
|
||||
/// `geometry_epoch`: a layer colour toggle can reuse the index, invalidate
|
||||
@@ -1950,6 +1955,7 @@ impl Scene {
|
||||
annotation_affects_wires: std::cell::Cell::new(None),
|
||||
model_extents_cache: RefCell::new(None),
|
||||
entity_block_map_cache: RefCell::new(None),
|
||||
layout_type_names_cache: RefCell::new(None),
|
||||
dependency_index_cache: RefCell::new(None),
|
||||
associative_hatch_source_cache: RefCell::new(None),
|
||||
block_defn_cache: RefCell::new(HashMap::default()),
|
||||
|
||||
Reference in new issue
Block a user