Skip to content

Add reference depth control to viewer for performance#246

Open
MatthewMckee4 wants to merge 9 commits into
mainfrom
feat/viewer-depth-control
Open

Add reference depth control to viewer for performance#246
MatthewMckee4 wants to merge 9 commits into
mainfrom
feat/viewer-depth-control

Conversation

@MatthewMckee4
Copy link
Copy Markdown
Owner

Summary

  • Add a "Depth" spinner (0–99) in the viewer status bar that controls how deep cell references are expanded when streaming elements
  • At depth 0, only the selected cell's bounding box with its name is shown
  • At depth 1 (default), the cell's own geometry renders and sub-cell references appear as labeled bounding boxes
  • Higher depths expand references further before showing bounding boxes at the leaf level
  • This prevents loading millions of elements for deeply nested GDS files, dramatically improving load times

Changes

  • state.rs: Add render_depth to CellState (default 1) and RenderCache for cache invalidation
  • app.rs: Add depth spinner UI, modify select_cell() to use depth-controlled streaming (stream_elements(Some(depth-1))), update zoom_to_fit for depth-0
  • drawable.rs: Add show_ref_bbox flag to DrawContext, add draw_ref_as_bbox() that renders un-flattened references as outlined rectangles with centered cell name labels
  • viewport/mod.rs: Pass depth info through to DrawContext, add depth-0 rendering path with cell bbox + label

Test plan

  • All 918 existing tests pass
  • New rerender_on_render_depth_change test verifies cache invalidation when depth changes
  • Manual testing: open a GDS file, change depth in the spinner, verify bounding boxes appear at leaf references
  • uvx prek run -a passes all checks

Adds a "Depth" spinner in the status bar that controls how deep cell
references are expanded when streaming elements. At depth 0 only the
cell's bounding box is shown; at depth 1 (default) the cell's own
geometry is rendered and sub-cell references appear as labeled bounding
boxes; higher depths expand further. This prevents loading millions of
elements for deeply nested GDS files.

- Add render_depth field to CellState and RenderCache for invalidation
- Modify select_cell() to stream with depth-1, skip streaming at depth 0
- Add draw_ref_as_bbox() to render un-flattened references as outlined
  rectangles with centered cell name labels
- Add show_ref_bbox flag to DrawContext, set when depth > 0
- Handle depth-0 rendering in viewport with cell bbox + label
- Update zoom_to_fit to compute bounds from cell bbox at depth 0
@MatthewMckee4 MatthewMckee4 added performance Performance improvements viewer GDS viewer and visualization labels Mar 9, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 9, 2026

Codecov Report

❌ Patch coverage is 12.50000% with 182 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/gdsr-viewer/src/drawable.rs 0.00% 79 Missing ⚠️
crates/gdsr-viewer/src/viewport/mod.rs 0.00% 56 Missing ⚠️
crates/gdsr-viewer/src/app.rs 0.00% 46 Missing ⚠️
crates/gdsr-viewer/src/state.rs 96.29% 1 Missing ⚠️
Files with missing lines Coverage Δ
crates/gdsr-viewer/src/state.rs 92.24% <96.29%> (-0.05%) ⬇️
crates/gdsr-viewer/src/app.rs 0.00% <0.00%> (ø)
crates/gdsr-viewer/src/viewport/mod.rs 53.80% <0.00%> (-5.64%) ⬇️
crates/gdsr-viewer/src/drawable.rs 57.96% <0.00%> (-4.12%) ⬇️

... and 2 files with indirect coverage changes

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

MatthewMckee4 and others added 8 commits March 9, 2026 14:20
When elements are re-streamed (e.g. on depth change or cell switch),
the tessellation cache retained earcut indices from previous elements.
If the new element at the same index had a different vertex count, the
stale cached indices would reference non-existent vertices, causing an
"Invalid mesh" panic in epaint.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Reference bounding boxes drawn by depth control were being hidden by
two layers of LOD culling:

1. Spatial grid cell-level: cells <1px were skipped entirely, and cells
   <24px were drawn as simplified rectangles without calling individual
   element draw methods — so references never got their bbox drawn.

2. draw_ref_as_bbox min-size cull: bboxes <2px were skipped.

Fix: remove the min-size cull from draw_ref_as_bbox (the rectangle
should always be visible), and when show_ref_bbox is active, allow
references to bypass spatial grid LOD culling so they are always drawn
regardless of zoom level.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Reference::world_bbox() returns None for Instance::Cell (cell name
references) because as_element() returns None for that variant. This
means cell references are never placed in the spatial grid, so the
spatial grid render loop never encounters or draws them.

Fix by adding a second pass after the spatial grid loop: when
show_ref_bbox is active, iterate all elements and draw any unseen
references. Also reverts the previous LOD bypass complexity since
the real issue was references not being in the grid at all.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Remove the min clamp on font size so the label scales proportionally
with the bbox (15% of the shorter side). Text is hidden when the bbox
is too small for readable text (shorter side < 40px on screen).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The 24px cap prevented the text from scaling with the bbox at large
zoom levels. Now the font size is fully relative (15% of shorter side)
with no upper bound.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Size the label to fit inside the bbox: width is divided by character
count (monospace approximation) and height is constrained to 40% of
the box height. The text scales down to 1px and is capped at 48px,
so labels never overflow into neighboring references.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replaces the text-input DragValue with a "Depth: N" label flanked by
small +/− buttons for easier one-click adjustment.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add minimum screen-size check (40×20 px) before computing font size,
ensuring labels are never rendered when the bounding box is too small
to contain readable text regardless of cell name length.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Performance improvements viewer GDS viewer and visualization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant