Skip to content
  1. Docs
  2. enzUI framework
  3. Developers

Performance observer

Measuring input-to-frame latency with iced's opt-in performance observer, and producing repeatable workload reports.

The enzICED fork has an opt-in timing spine behind iced's performance-observer Cargo feature. Compiling the feature does not start collection: until iced::performance::enable(Config { .. }) is called, every runtime hook is a cold atomic branch and allocates nothing.

rust
use iced::performance::{self, Config};

performance::enable(Config::default());
// Run the interaction.
print!("{}", performance::to_ndjson());
performance::disable();

The winit runtime timestamps input arrival, event-queue wait, input dispatch, invalidation, view rebuild, tree diff, layout, draw preparation, GPU submission and the strongest available frame milestone, against one monotonic clock and iced's window id. to_ndjson() emits one JSON object per observed window. For one window, use snapshot(WindowId(window_id.as_u64())) with the real iced::window::Id.

Collection is process-wide. enable starts a new session; disable stops collecting without clearing the results.

Timestamp quality is part of the result

The latency is named input_to_milestone, not input_to_visible. Read presentation_quality with every result; when a window has samples of different qualities, compare with input_to_milestone_by_quality.

QualityMeaning
SubmittedCommands reached the GPU queue. This is not "the user saw it": the frame may still wait on the surface, compositor or vsync. Offscreen benchmarks report this.
SurfacePresentedThe backend returned from its present call (for wgpu, SurfaceTexture::present()). It still does not prove the compositor showed the frame.
CompositorPresentedA platform integration supplied actual compositor feedback. The common path never invents this value.

For claims about what the user saw, use an external capture (a display, photodiode or capture clock) and publish it beside the observer's milestone, not in place of it.

Bounds and allocation

Config bounds the memory it keeps:

  • trace_capacity defaults to 4,096 events, preallocated at enable. When the ring wraps, dropped_trace_events counts it.
  • max_windows defaults to 64. Events for further windows increment dropped_window_events.
  • Every duration uses a fixed 257-bucket logarithmic histogram. Histograms never evict samples; snapshots expose count, p50, p95, p99 and exact max.

Collection does no steady per-event or per-frame allocation; only the snapshots and JSON you request allocate.

What to record

Representative workloads include shell label clicks, modal typing, a 10,000-row virtual-list scroll, a 1 MiB reading pane and a ten-second 60 Hz animation. Record machine, GPU, backend, release profile, resolution, scale, sample count, CPU, RSS, VRAM and allocations with every published run. Do not use a headless layout duration or the offscreen Submitted milestone as a visible-response baseline.

Repeatable workload reports

enzui_core::perf_report (feature perf-report, test-only) drives scripted page switches, animations, scrolling and idle holds over an app that implements perf_frame::PerfSubject:

rust
use enzui_core::perf_report::{CaptureProvenance, Workload, WorkloadDriver};
use iced_core::Size;

let capture = CaptureProvenance::from_env().expect("runner supplied complete provenance");
let mut driver = WorkloadDriver::new(app, Size::new(1200.0, 800.0), 1.0, capture);
let report = driver
    .run_observed(&Workload::busy_scroll(
        "virtual list",
        "5000 rows, 300 realised",
        (0..64u16).map(Msg::Scroll),
    ))
    .expect("a non-empty workload reports");
println!("{}", report.to_json());

A WorkloadReport records the workload's identity, full build and machine provenance, frame count, p50/p95/p99/max paint and layout histograms, the worst per-frame page rebuild count, CPU and RSS (and VRAM where the backend reports it), the milestone quality and any dropped events. run_observed folds in the runtime observer's view, diff, layout, draw-preparation and submit histograms. Both run and run_observed report Submitted milestones; neither measures native window presentation.

The report and comparison APIs refuse misleading inputs:

  • an empty workload is PerfError::EmptyWorkload, never a report of zero;
  • a Submitted milestone asked to stand for what the user saw is PerfError::SubmittedClaimedVisible;
  • a comparison involving a run that dropped events is PerfError::DroppedTraces;
  • too few frames, or a comparison across backend, profile, GPU, workload, build config, features, lockfile, milestone quality, resolution or scale, is PerfError::Underpowered or PerfError::Incomparable.

Capture identity

CaptureProvenance::from_env requires ENZUI_PERF_APP_NAME, ENZUI_PERF_APP_VERSION, ENZUI_PERF_APP_REV, ENZUI_PERF_FRAMEWORK_REV, ENZUI_PERF_VENDOR_REV, ENZUI_PERF_LOCK_SHA256, ENZUI_PERF_CONFIG, ENZUI_PERF_FEATURES and ENZUI_PERF_GPU. Empty or unknown values are rejected, and the lock digest must be a SHA-256 hex value. Use the actual release binary for published measurements and record the exact command and environment with the result.

Lighter-weight tools

  • ENZUI_FRAME_COST=1 logs shell layout durations and frame intervals.
  • ICED_SPAN_TRACE=<file> appends the start and duration of every update, view, layout, draw, replay and present.
  • iced's devtools and Comet show frame timings and message rates live.

See Developer tools.