From 91b2344db1a7ca59ae8b23072e05806d151a1b63 Mon Sep 17 00:00:00 2001 From: Panos <25664832+mechpanos@users.noreply.github.com> Date: Sat, 5 Sep 2026 15:17:32 +0300 Subject: [PATCH] perf: break the grid overlay down by part MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `view-detail` located the first paper frame's cost precisely: 7826.9 of 7832.8 ms in `grid`. Once, on the first frame after a layout switch — every other frame in a 2769-frame session reports it at 0.0. That is the largest single cost in a layout switch, larger than the model re-tessellation and the arena rebuild combined, and it is not geometry work at all. `grid_overlay` itself only wraps a canvas; `grid_segments` runs later, in `draw`. So the time is in `grid_views` or in the per-view parameter build, and reading the two does not settle which: both reach helpers that can fall back to a full document walk, and neither obviously fires for this drawing. `grid-detail views= params= bg= n=` splits it, and reports only when the block costs at least a millisecond so the quiet frames stay quiet. Co-Authored-By: Claude Opus 5 --- src/app/view/mod.rs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/app/view/mod.rs b/src/app/view/mod.rs index 78962a4b1..864496a60 100644 --- a/src/app/view/mod.rs +++ b/src/app/view/mod.rs @@ -382,9 +382,15 @@ impl OpenCADStudio { ); (o, (ux.as_vec3(), uy.as_vec3(), uz.as_vec3())) }; - let grid: Vec = tab - .scene - .grid_views(vw, vh) + // The first paper frame spends seconds in this block and `grid` + // alone cannot say which part. Reported only when it costs + // something, so ordinary frames stay quiet. + let t_grid = crate::perf::enabled().then(iced::time::Instant::now); + let views = tab.scene.grid_views(vw, vh); + let views_ms = crate::perf::elapsed_ms(t_grid); + let view_count = views.len(); + let t_params = crate::perf::enabled().then(iced::time::Instant::now); + let grid: Vec = views .into_iter() .map(|(bounds, cam, handle)| { let (origin, mut axes): (glam::DVec3, _) = if is_paper { @@ -428,7 +434,16 @@ impl OpenCADStudio { } }) .collect(); + let params_ms = crate::perf::elapsed_ms(t_params); + let t_bg = crate::perf::enabled().then(iced::time::Instant::now); let bg = crosshair_background(tab, is_paper); + let bg_ms = crate::perf::elapsed_ms(t_bg); + if views_ms + params_ms + bg_ms >= 1.0 { + crate::perf_record!( + "[perf] grid-detail views={views_ms:.1}ms params={params_ms:.1}ms \ +bg={bg_ms:.1}ms n={view_count}" + ); + } let bg_lum = 0.299 * bg[0] + 0.587 * bg[1] + 0.114 * bg[2]; let grid_style = crate::ui::overlay::GridStyle { opacity: self.model_space.grid_opacity,