Repository navigation
perf: per-frame input-to-present latency probe on metal - #5105
Conversation
Every rendered frame now gets a frame id and steady-clock stamps for its last OS-event poll, RENDER's cursor sample, its loop-iteration start and its last commit. The render device reports when the frame ended through a non-blocking query on RenderDevice that defaults to "not measured", so the OpenGL device compiles unchanged and reports no reading. Metal reports the command buffer's GPU end, moved from host time onto the steady clock with a bounded mapping error. The --auto-profile report gains an Input latency section: mean, p99 and max of input_to_present, cursor_to_present, frame_start_to_submit and submit_to_present over the steady frames, frames in flight at frame start, the clock mapping bound, and the per-frame series. The probe rides on frame timing and reads no clock when it is off. input_latency_test_delay_ms is the positive control's test-only sleep between the last poll and RENDER. repeat_profile.py parses and summarizes the section and admits IRShapeDebug's default scene, which the serialized baseline in docs/perf/input-latency/ uses as its light scene. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Keeps the new scripts/perf/README.md section clear of the lines another open PR inserts beside the frame decomposition section. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Moves the input latency parser patterns up beside the steady frame pattern, out of the lines an open stacked PR rewrites next to the device counter patterns. No behaviour change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Perf gateHead host slug: Perf gate — seeding new baselineNo baseline at |
jakildev
left a comment
There was a problem hiding this comment.
Review — perf: per-frame input-to-present latency probe on metal
Verdict: approve
The frame-loop/device pairing is coherent: frame identity is independent of submission serials, the Metal path timestamps the existing final commit/wait without adding GPU work, late completions remain non-blocking, and the disabled/OpenGL-default paths read no clock and report not measured. I found no correctness, lifetime, synchronization, or hot-path allocation defect in the reviewed diff.
Praise
InputLatencyAccumulatorkeeps report rows parallel with rendered frames while pairing completions by stable frame id; the late, skipped, invalid, and no-poll cases are explicit and covered.- The Metal clock conversion records both observation lag and a bounded host-to-steady mapping error instead of treating CPU observation time as GPU completion.
- The committed baseline includes the positive control, three scene classes, parent/head submission counts, and enough run metadata to make later overlap comparisons meaningful.
Acceptance (issue #4998)
| Criterion | Grade | Evidence |
|---|---|---|
| 1. Report fields, ordered series, end kind, frames in flight, and full steady-frame coverage | Met | writeInputLatency emits the required fields; the committed 120-frame report records 90 steady frames and 90 samples. The focused C++ suite covers pairing and report forms. |
| 2. Three interleaved 20 ms positive-control pairs | Met | The rises are 18.618, 18.496, and 19.114 ms, all within 2 ms of 20, with 225/225 samples. Each manifest records a guarded quiet window. |
| 3. Metal reports measured zero in flight; OpenGL is distinct | Met | Metal reports gpu-complete and max 0; base-device/report tests distinguish not measured from zero. Plan correction A1 assigns the OpenGL implementation to #5001. |
| 4. Three Release scene classes across three interleaved rounds with noise bounds | Met | Nine guarded, clean manifests cover light, GPU-bound million, and CPU-bound fixtures; the baseline gives means, p99s, frame/update context, host load/power, and between-run spreads. |
| 5. No added wait/submission; disabled path reads no clock | Met | Parent/head reports retain 120 command buffers for 120 valid frames in both fixtures. The implementation instruments the existing Metal commit/wait, and disabled-path tests assert zero clock reads. |
Validation
- Local reviewed-head build:
fleet-jobs: 20261116T122938Z-build-2f5f64 succeeded exit=0forIrredenEngineTest. - Local reviewed-head C++ tests:
fleet-run IrredenEngineTest --gtest_filter='InputLatency*'— 15 passed. - Local parser/summary tests:
python3 -m unittest test_profile_parser.py test_repeat_profile.py test_shape_profile.py— 119 passed. - Live CI: perf-gate, fleet-tests, format, headers, lint, and other completed checks pass.
render-harness-testsis red on the existingscripts/verify_common.pyimport offleet; the latest master run fails the same dependency-contract assertions, so this is inherited rather than introduced by #5105.linux-buildwas still pending when reviewed.
Test plan before merge
- Let the pending
linux-buildfinish; do not treat it as green until it completes.
🤖 Reviewed by Codex GPT-5 (review-pr skill)
Opus recheck not required (reviewed at opus class).
Summary
engine/render/include/irreden/render/input_latency.hpp):InputLatencyAccumulatorkeeps the last OS-event poll, opens one record per RENDER (frame id from a World-owned counter, cursor-sample time, loop-start time, frames in flight at frame start), and closes it when the device reports that frame's end, including an end that arrives frames later. A frame with no poll of its own keeps the most recent earlier poll. Records stay parallel to the report's frame series, reserved once inenableFrameTiming. Disabled, no method reads a clock.RenderDevice):setPresentingFrame(id), a never-blockingpollFrameCompletion(),framesInFlight()andframeEndEvent(), backed by aFrameCompletionQueuethat defaults toNOT_MEASURED. The OpenGL device is untouched and reports "not measured". Metal stamps the submission at commit and reports the command buffer'sGPUEndTime, converted from host time tosteady_clockwith an offset read between two host-clock reads (half their gap bounds the mapping error). A mid-framefinish()does not touch the queue, so frame ids never followsubmissionSerial().--- Input latency ---): end event (gpu-complete/not measured), steady-frame count and sample count, mean / p99 / max ofinput_to_present_ms,cursor_to_present_ms,frame_start_to_submit_ms(CPU) andsubmit_to_present_ms(GPU), max frames in flight at frame start, the end-observed lag and clock-mapping bound, and a per-frame--- Input to present ---series (-= no end). Works in Release.input_latency_test_delay_msWorldConfig key (default 0) sleeps between a frame's last poll and RENDER;creations/demos/shape_debug/configs/perf/input-latency-delay-20ms.luasets it to 20.compare_perf_runs.parse_reportreads the section intoinput_latency(Nonewhen absent;measuredfalse for not measured).repeat_profile.pyadds per-run mean/p99 rows and a per-run coverage table, and admits IRShapeDebug's default scene (--sdf-voxel-scene off, no SDF workload controls, no SDF witnesses) plus the delay preset.perf_grid/configs/perf/profiling-off.luais the default IRPerfGrid scene with stage profiling off.docs/perf/input-latency/README.mdholds three scenes × three interleaved Release rounds, with each row's between-run spread as its noise bound, plus the positive-control pairs and the parent-vs-head command-buffer reports.Test plan
fleet-build --target IrredenEngineTest, thenfleet-run IrredenEngineTest --gtest_filter='InputLatency*':[ PASSED ] 15 tests(accumulator pairing, a late end, an earlier poll kept, no reading before any poll, a skipped end, an invalid end, the disabled path reading no clock, queue order and in-flight count, the base device reporting not measured, a blocking-present device leaving 0 in flight, and the report section's steady-frame statistics, not-measured and no-sample forms).fleet-run IrredenEngineTest(Debug, macOS Metal):[ PASSED ] 3848 tests, 3 skipped (platform skips: two buffered-I/O failure injections andFogCrossSectionTest.SkippedOnNonOpenGLBackend).python3 -m unittest discover -p 'test_*.py'inscripts/perf(174 tests OK) and inscripts/perf/tests(7 OK);ruff check scripts/: All checks passed.fleet-build --target format-changed: no change to the committed tree.fleet-pr-overlap --base master:VERDICT: overlap(exit 1), rows quoted in Notes for reviewer.caffeinate -d -i -u python3 scripts/render-verify.py --target IRShapeDebug --no-build:20 of 148 checks FAIL (10 skipped — references pending). Every failing row is master's, and every failing pass renders pixel-identically on master. A master345dbbf25Debug tree built in the same session renders the same set of PNG SHA-256s as this head for each pass with a red row: default 28/28,sdf_baked_surface_parented6/6,sdf_baked_pose_root6/6,sdf_baked_pose_parented6/6,glitch_standard_off28/28,glitch_subject_standard_off28/28, andlod_scene(one SHA-256 across three head and three master runs).lod_scene:lod_scene_fine_yaw90(match 96.150 %, PSNR 32.63 dB) was untracked; it is now posted on render: refresh stale macos-debug ShapeDebug and CanvasStress references #4904 with the master measurement.Acceptance evidence
fleet-run IrredenEngineTest --gtest_filter='InputLatency*'(15 PASSED);fleet-build --target IRPerfGrid, thenfleet-run IRPerfGrid --auto-profile 120 --no-overlay(Debug,QUIET=guarded,paced at 120 Hz)End event: gpu-complete,Steady frames: 90 (first 30 of 120 excluded) samples=90,input_to_present_ms: mean=11.512 p99=18.528 max=18.528,Frames in flight at frame start: max=0, and a 120-value (0 without an end)--- Input to present (ms, in order; - = no end) ---series. Report committed atdocs/perf/input-latency/report-fields/irperfgrid-debug-120.txt.repeat_profile.py --target IRShapeDebug --repeats 1 -- --auto-profile 300 --yaw 0 --zoom 1 --sdf-voxel-scene off --config-preset configs/perf/<sdf-off | input-latency-delay-20ms>.lua, three pairs interleaved, every runQUIET=guarded(see Plan departures on the benchmark lease)docs/perf/input-latency/positive-control/.InputLatencyRenderDevice.ADeviceThatTimesNoFrameEndReportsNotMeasured,InputLatencyReport.ADeviceWithoutFrameEndsIsNotMeasuredRatherThanZeroFrames in flight at frame start: max=0underEnd event: gpu-complete. A device that times no frame end (the OpenGL device, untouched here) writesEnd event: not measured/Frames in flight at frame start: not measuredand no statistic row. The OpenGL reading belongs to #5001 per Plan correction A1.docs/perf/input-latency/: Release, stage profiling off, three interleaved rounds of light / million / CPU-bound (probe CPU > GPU); mean and p99, frame mean, updates per frame, power, host load, between-run spread as the noise bound; quiet-host verdictrepeat_profile.py --release --repeats 1per cell with the per-scene arguments in the doc's Scenes table; rounds a → b → c, three times, ReleaseQUIET=guarded,RESULT=CLEAN, AC power, 225/225 samples.input_to_present_msmean (spread): light 10.344 (1.098), million 26.250 (0.118), CPU-bound 15.753 (0.140); p99 (spread): 16.099 (1.700), 26.989 (0.361), 23.507 (2.119). CPU-bound scene (IRPerfGrid default scene,--worker-threads 0) reads CPU 9.61 > GPU 4.01 ms; million reads 8.51 / 19.14. Load average 5–12 is stated per row. The pacer fix227cadbecis in the tree, and the doc says so.fleet-run --build-dir <tree> IRPerfGrid --auto-profile 120 --no-overlayand the million control at 120 frames, Release, on this head and on a parent (345dbbf25) tree;InputLatencyAccumulator.DisabledTakesNoTimestampAndRecordsNothing,InputLatencyFrameCompletionQueue.DisabledOrUnmeasuredReadsNoClockCoverage: supported=1 attempted=120 valid=120 invalid=0 commandBuffers=120at both fixtures. The disabled-path tests count 0 clock reads. Reports indocs/perf/input-latency/command-buffers/.Plan departures
gpu-completein both window modes, and the report names that end event.FrameEndEvent::PRESENTEDand the late-arrival path in the accumulator are ready for a device that adds it.ir-acquire benchmark". An outerir-acquire benchmark -- …hold makes every nestedir-run --auto-profileinherit the lease, so it opens no guarded window and prints noQUIET=line. Each run instead took its own guarded window throughfleet-run, and every manifest recordsquiet: guarded.repeat_profile.py. Its IRShapeDebug path accepted only the SDF fixtures. It now also admits--sdf-voxel-scene off, IRShapeDebug's default scene with an explicit--yaw 0 --zoom 1(the defaults), and the delay preset.--worker-threads 0, through a newconfigs/perf/profiling-off.luapreset.frame_start_to_submit_msis the frame's CPU time. It is the probe-side witness that scene (c) is CPU-bound ("the probe's own CPU time per frame exceeds its GPU time").Notes for reviewer
fleet-pr-overlap --base master,VERDICT: overlap). Every row is a conflict render: size per-axis stores from content height (#4960) #5101 (stacked on render: reject hidden overflow-lane faces before sort, relight and draw (#4954) #5084, forked before master moved) already has with master:scripts/perf/README.mdsection and its parser regexes clear of engine: stop paying per-update work for resident entities that cannot change (#5009) #5073's and render: size per-axis stores from content height (#4960) #5101's hunks. On all three paths, a-c merge.conflictStyle=mergetrial merge against render: size per-axis stores from content height (#4960) #5101 gives the same conflict blocks from the merge-base as from this head, andgit merge-filereplays this branch onto the merge-base result with exit 0.input_to_presentalternates by about one frame (8.3 ms). This is real latency, surfaced as the plan asked. The delayed control arm always polls, which is why its rise is 18.5–19.1 ms rather than exactly 20. The doc spells this out.RESULT=NO-DISPLAYwhen the display slept, and some CPU-bound scouting runs before that read the 60 Hz pacer fallback. Those scouting runs only picked the scene. Every committed run was taken undercaffeinate -d -i -uwith 120 Hz pacing confirmed in Debug before and after.engine/render/CLAUDE.md, "Changes without a visual effect need no captures"). Render-verify, in the test plan, is the unchanged-output check.Closes #4998
🤖 Generated with Claude Code