From 15425298b768fecdcf58bbe9e26c9c65326a0698 Mon Sep 17 00:00:00 2001 From: Panos <25664832+mechpanos@users.noreply.github.com> Date: Fri, 4 Sep 2026 14:10:47 +0300 Subject: [PATCH] perf: measure widget-tree construction Everything measured so far accounts for about 1 ms of a ~120 ms pan frame: update is 5-28 ms at worst and usually far less, prepare 0.45 ms, encode 0.5 ms. Meanwhile the GPU idles at 0-8%, encoding no scene at all leaves latency unchanged, major page faults stay flat at 17 across forty seconds of panning, and freeing 6 GB of swap changes nothing either. So the time is in code that has never been timed. `view()` runs between the input handler returning and `prepare` being called, rebuilds the whole widget tree every frame, and is the largest unmeasured span in that gap. Reports only when it exceeds 1 ms, so a healthy frame stays quiet. Co-Authored-By: Claude Opus 5 --- src/app/view/mod.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/app/view/mod.rs b/src/app/view/mod.rs index b293a6ca3..f5fb51fd5 100644 --- a/src/app/view/mod.rs +++ b/src/app/view/mod.rs @@ -192,7 +192,20 @@ impl OpenCADStudio { // All dialogs are in-canvas modals now (Plan B); view_main stacks the // active one. `window_id` is unused — there is only the main window. let _ = window_id; - self.view_main() + // Pan latency on a large drawing is ~120 ms while `update`, `prepare` + // and `encode` together account for ~1 ms of it, the GPU sits at 0-8%, + // and encoding no scene at all changes nothing. Widget-tree + // construction is the largest span between the input handler returning + // and `prepare` running, and it was never measured. + let started = crate::perf::enabled().then(iced::time::Instant::now); + let element = self.view_main(); + if let Some(started) = started { + let elapsed_ms = started.elapsed().as_secs_f64() * 1000.0; + if elapsed_ms >= 1.0 { + crate::perf_record!("[perf] view {:>7.1}ms", elapsed_ms); + } + } + element } /// The primary window: viewport, ribbon, tab bar, status bar. Split out of