perf: don't resolve viewport cameras for a grid nobody draws

`grid-detail` came back `views=1095.2ms params=0.0ms bg=0.0ms n=0`. Zero
grid views — every millisecond of it thrown away.

`grid_views` asked `active_viewports` for every viewport, which resolves a
camera for each, and `camera_for_viewport` reaches `model_space_extents`,
which outside the Model layout tessellates the whole drawing. Only then
did it filter on `grid_on`, which removed all of them. The parallel walk
from the previous commit had already cut this from 7826.9 ms; it was
7.8 seconds of work for an empty vector.

`grid_views` now asks first. `any_viewport_grid_on` reads the same fields
`active_viewports` copies into `ViewportInstance::grid_on`, and skips the
visibility filters that function also applies: answering "maybe" costs
only the work that would have happened anyway, while answering "no"
wrongly would drop a grid the user asked for.

Also reports the tessellation memo's guard and the inputs that can move
it. Two consecutive identical resident builds each missed all 186 455
entries — `memo_hit=0` twice in a row — which a stable guard cannot
explain, so something is clearing the memo between them and reading the
code has not said what. `guard=`, `guard_stale=`, `avp=`, `anno=`,
`anno_h=`, `all_vis=` and `sdf_gen=` will.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
PanosandClaude Opus 5 committed 2026-09-05 18:53:02 +03:00
1 parent 0b4551b6ec
commit d9a1d55f2e
2 files changed
+46 -2

No files matched your search

+29
View File
@@ -69,7 +69,36 @@ impl Scene {
(layout_block, sheet, content)
}
/// Could any viewport in this layout draw a grid?
///
/// Read from the same fields `active_viewports` copies into
/// `ViewportInstance::grid_on`, and deliberately without the visibility
/// filters that function also applies: answering "maybe" only costs the
/// work that would have happened anyway, while answering "no" wrongly
/// would drop a grid the user asked for.
fn any_viewport_grid_on(&self) -> bool {
if self.current_layout == "Model" {
return self.model_tiles.borrow().iter().any(|tile| tile.grid_on);
}
let (_, sheet, content) = self.paper_viewport_handles();
let grid_on = |handle: Handle| {
matches!(
self.document.get_entity(handle),
Some(EntityType::Viewport(vp)) if vp.status.grid_on
)
};
grid_on(sheet) || content.iter().copied().any(grid_on)
}
pub fn grid_views(&self, vw: f32, vh: f32) -> Vec<(iced::Rectangle, Camera, Handle)> {
// `active_viewports` resolves a camera for every viewport, and
// `camera_for_viewport` reaches `model_space_extents`, which outside the
// Model layout tessellates the whole drawing. Filtering on `grid_on`
// afterwards threw all of that away: on the reproducer the first paper
// frame spent 7.8 s here to produce `n=0` views. Ask first.
if !self.any_viewport_grid_on() {
return Vec::new();
}
self.active_viewports(vw, vh, acadrust::entities::ViewportRenderMode::Wireframe2D)
.into_iter()
.filter(|inst| inst.grid_on)