Skip to main content

Module perf

Module perf 

Source
Expand description

Where a frame’s milliseconds go — the per-frame timing record behind the __brepPerf blob and the Info window’s Performance rows. Where a frame’s milliseconds go — the ONE per-frame timing record.

A dropped frame rate and a frozen UI are the same fact on wasm: the app is single-threaded, so every millisecond spent between two ui() calls is a millisecond the browser cannot deliver a pointer event in. “Slow” is therefore not one number but a split, and the split is what names the owner: encode-and-submit time is the renderer’s, publish time is the state registry’s, and the gap between them is egui’s.

Measured with web_time::Instant, which is performance.now() on wasm and the monotonic clock natively, so both shells report the same quantity.

§Why a static, and why accumulate

The phases are timed in three different modules (app, viewport, viewport::blit) that do not share a &mut path, so the record lives here as a static — the same shape crate::automation::registry uses, for the same reason. A phase may be entered SEVERAL times in one frame (the registry publishes from three places); each entry accumulates, and tick — called once at the top of the frame — banks the frame’s totals into the rolling window. So every reported phase is “ms per frame”, never “ms per call”.

dt is wall time between successive ticks: the frame PERIOD, including whatever the browser did between our frames. It is the number a user feels; the phases explain it.

Structs§

Span
Trace

Enums§

Phase
The timed phases, in report order. Ui brackets the whole of BrepApp::ui; the rest are nested inside it and do not sum to it — the remainder is egui’s own layout, painting and tessellation.

Functions§

json
The rolling window as JSON: the __brepPerf blob and the Info-window rows read this one value, so they cannot disagree.
note_stale_frame
reset
Drop every sample, keeping the frame counter’s meaning (“frames banked”) intact only for the new window. A measurement resets, then spins, then reads — otherwise the idle frames before the spin dominate the average.
span
Time a block into phase; the span ends when the guard drops. Several spans of the same phase in one frame ADD UP — the window holds ms per frame.
tick
Open the current frame: bank the previous frame’s phase totals and record its period. Call ONCE, at the top of BrepApp::ui.
trace
A scratch phase timer for one block of the frame: with BREP_FRAME_TRACE=1 it writes [frame-trace] <label> <ms> to stderr when the block took longer than 250 ms, and costs one clock read otherwise. What finds the phase that holds a frame for seconds when perf/ptrace are unavailable.