perf(mods): the mod runtime's per-frame cost counted (HOS_FRAME_COST) and cut #2880

Closed
HumanBean wants to merge 3 commits from cleanup/area7-frame-cost into mod-api
Owner

Summary

On mod-api the game's main thread spends more CPU a frame than on main; the gap was about 0.17 ms and no code path
read explained it. This PR first measures where the time goes, then cuts what the numbers pointed at.

  • The counters. HOS_FRAME_COST=1 (a diagnostic switch, off by default) logs a few frame cost: lines every 10 s:
    the CPU time a frame of each named step of the game side's acquire phase (the loader's, each native system mod's
    frame, every services step), and every hook site's hits and time a frame, the main thread's apart from the other
    threads'. The plain trampoline's sites (the engine's own Rust callbacks) count their hits too while it is on. The
    frame trace (RX_VK_FRAME_TRACE=1) has a new column, acquire_cpu_ms: the main thread's CPU time inside
    game_phase_run, the whole of the mod runtime's frame, read around the call in host/nn_vi.c (two thread-clock
    reads a frame, only while the frame is timed) and handed to the renderer as MkwVkHost.main_thread_times' fourth
    value (API version 82).
  • What they showed (Hyrule Field, below): the gap is the acquire phase; the hook sites on the main thread cost
    next to nothing (the ones with time there are the barrier fix's sleeps, which main has too). The phase is many small
    steps, none big: the settings host's step, the renderer status the HDR mod reads, the loader's manifest check, the
    timers, the input step, the UI's frame end, each 2 to 8 us.
  • The cuts (commit 2): the timers step walks only the mods that have timers (it copied the load order and made two
    lists for every running mod each frame); the load order is shared (Rc), so the steps that walk it take a count, not
    a copy; the Insert menu's fallback does nothing unless it shows or is wanted; the loader's check of the linked
    manifests walks the list it set, in order, with no look-up by id; the frame event's payload is made only for a
    listener; the game's moments make no listener list for an event nobody listens to; and one Rust function's handler
    around an empty core (widescreen's and sprint-walk's sites) takes the plain trampoline instead of the dispatcher:
    no chain loaded or walked, but still counted in the site's readers (its pointer tagged in PLAIN), so
    remove_retired/remove_then wait for a hook still in it, as they do for the dispatcher (commit 3).

Read first: game/crates/game-sites/src/cost.rs, chain.rs's publish, api/src/services/time.rs's timers_step.

Testing

Tested: Linux (CachyOS 7.3.3), RTX 3090, NVIDIA 620.70.06. In the game, Hyrule Field (child), 1080p native, six
measured runs of 60 s through dev.py ab (below): every system mod started, no fault, the frame trace's
acquire_cpu_ms filled on this PR's side. Before the cuts, two runs with HOS_FRAME_COST=1 logged their frame cost:
lines every 10 s (the numbers in Summary). Checks: cargo clippy -D warnings and cargo test of game-sites, api,
longshot-game and the widescreen, sprint-walk and shadows system mods; tests/run_all.py --changed (204 checks: one
failed, test_pacing_policy.py, fixed by giving its fixture the thread clock, then passed with
test_frame_trace_waits.py); the renderer compiled for Windows with llvm-mingw. The host's Windows compile
(check_host_compile.py) compiled every unit but host/nn_video.c, which needs FFmpeg's headers this PC's setup
does not give it (not a file this PR changes; host/nn_vi.c compiled). After the review fix and the rebase onto
mod-api @ 75bcd270 (one build-mode queue job): clippy -D warnings and cargo test of game-sites (with fake),
api and longshot-game, tests/run_all.py --changed, scripts/shaders.py all and the whole Windows host compile
(check_host_compile.py, llvm-mingw, with FFmpeg's headers) all passed. game-sites' new test
a_lone_function_handler_removed_while_running_waits_for_it fails without the readers' count and passes with it. game-sites' retire tests fail now and then
under load, on mod-api too (5 runs in 25 there): not this PR's.

Still to test:

  • Windows (any GPU): a frame trace run (RX_VK_FRAME_TRACE=1), expecting acquire_cpu_ms filled and below
    main_cpu_ms; HOS_FRAME_COST=1 logs its frame cost: lines every 10 s (@Beanstalk run Hyrule Field with
    RX_VK_FRAME_TRACE=1 and HOS_FRAME_COST=1 and attach the log's frame cost lines)
  • The lab PC (RX 580): the same A/B as below, expecting the same direction (by hand)

Measurements

Verdict: the main thread is 0.09 ms a frame over main now (2.018 against 1.928 ms), of which 0.066 ms is the mod
runtime's acquire phase. Average fps is within 1 % of main (139.2 against 138.0). The 1% low (125.4 against 117.0,
-6.7 %) and p99 (7.98 against 8.55 ms, +7.1 %) are noisy and inconclusive: their runs spread from 80 to 126 fps. The cuts' own share was not measured apart (no
mod-api side was run): from the counters' per-step numbers they save about 10 to 15 us a frame (the timers 3 to 4 us,
the manifest check about 4, the fallback about 2, the load-order copies and the moments' lists a few). The gap is not
closed: what is left is the many 1 to 8 us steps above, the settings host's step and the renderer status the HDR mod
reads being the biggest (area 2 and area 3 change those).

Setup: Linux, RTX 3090, NVIDIA 620.70.06; Hyrule Field (child), output 1920x1080, Render resolution 100 %, no upscaler,
uncapped, V-Sync and frame generation off (dev.py ab --options native1080.ini, HOS_FPS_MAX=1000); A, B, A, B, A, B,
60 s each after the warm-up, the median of three. main_cpu_ms and acquire_cpu_ms are the frame trace's means over
the measured frames. A is main's own runtime at the fork point, unconfined as main runs (HOS_SANDBOX=0: main's
game cannot serve the control bridge inside the builder's sandbox); B is this PR's, confined by default, as a player
runs it.

These numbers are from before the rebase. They still hold: the rebase onto mod-api @ 75bcd270 brought in #2855
(rustfmt only), #2861 (where menu rows are placed: menu layout and settings listing) and #2881 (a mod's game language:
loader, manifest and init-time code). None of them runs per frame in Hyrule Field with the menu closed. The review fix
adds two atomics per hit on widescreen's and sprint-walk's sites. That is what the dispatcher counted before this PR,
without the chain load and walk. The user accepted the fps gap on this area, so the runs were not repeated.

Before: main @ 46291934 After: this PR @ 946cf164
fps 139.2 [131.6-139.3] 138.0 [131.9-138.5]
1% low fps 125.4 [80.6-126.3] 117.0 [85.5-124.8]
median / p99 frame ms 7.19 / 7.98 7.22 / 8.55
main thread CPU ms (main_cpu_ms) 1.928 [1.911-2.100] 2.018 [2.004-2.222]
its acquire phase ms (acquire_cpu_ms) (no column) 0.066 [0.065-0.075]

The third pair was noisy on both sides (p99 12 ms); the 1% low's median on B is its second run's (117.0; 124.8 and 85.5
the others). Run folder: ~/.local/share/longshot-dev/runs/ab/20261130-003115-hos_frame_cost-hos_sandbox-hyrule-field.
dev.py ab gave no write-up (exit 3): the sides differ in the menu's rows mod-api adds and in the sandbox's switches,
as every main against mod-api comparison does.

The counters' run (B with HOS_FRAME_COST=1, before the cuts, both sides confined then): acquire phase 0.133 ms with
the counters' clock reads; steps a frame: services 76 us, loader 38 (the native mods' frames 28, of which hdr 4.7),
settings host 7.9, the manifest check 5.7, input 4.0, UI frame end 3.9, timers 3.9, the game's moments 3.7, the file
watch 2.8, the menu fallback 2.3; sites on the main thread 52 us a frame, nearly all the barrier fix's sleeps
(barrier.sleepClaim), which main has too. Folder: ...runs/ab/20261129-215249-hos_frame_cost-hyrule-field.

Risks

  • The plain trampoline for a lone function handler counts itself in the site's readers and loads the function again
    once in. A publish off plain clears PLAIN, and a hook that read the old slot goes on to the dispatcher. So a removal's
    grace still waits for it. The site's hits are not counted in the stats for it (as for an owner) unless
    HOS_FRAME_COST=1.
  • main_thread_times now writes four values: host and renderer change together (API version 82).
  • Nothing changes for a player: no setting, file or cache.

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit. (into mod-api, on mod-api@origin 75bcd270)
  • Tested on my own PC, in the game for a change the game runs, as Testing says.
  • mise run test passes (any failure that also fails on main is named). (the whole tests/run_all.py on the head: 733 passed, 114 skipped, 1 failed: test_lifter.py's build-core test control::tests::the_socket_is_made_private_and_a_client_handed_over, in the builder's control socket, which this PR does not touch; it fails the same way on mod-api @ 12f42db5, checked in #2868's run)
  • Measured against main, or Measurements says why there is nothing to measure.
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • A switch added or changed: it ships at the default the measurements chose, with its row in gpu/vk/switches.def.
    (HOS_FRAME_COST, a diagnostic, off)
  • A check under tests/ that reads changed source is updated, not weakened. (tests/test_frame_trace_waits.py:
    the new column)
  • MKWVK_API_VERSION bumped (MkwVkHost or MkwVkRenderer in gpu/vk/vk_api.h changed).
  • Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths.
  • Docs updated. (docs/dev/reference/hooks.md, profiling.md)
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

Ready to merge

  • Everything in Still to test has run, its results in Tested.
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers").
  • Approved in review, every comment answered.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold.

🤖 Generated with Claude Code

https://claude.ai/code/session_016o1k1SQVyAWsujjFVd8Wuc

## Summary On `mod-api` the game's main thread spends more CPU a frame than on `main`; the gap was about 0.17 ms and no code path read explained it. This PR first measures where the time goes, then cuts what the numbers pointed at. - **The counters.** `HOS_FRAME_COST=1` (a diagnostic switch, off by default) logs a few `frame cost:` lines every 10 s: the CPU time a frame of each named step of the game side's acquire phase (the loader's, each native system mod's frame, every services step), and every hook site's hits and time a frame, the main thread's apart from the other threads'. The plain trampoline's sites (the engine's own Rust callbacks) count their hits too while it is on. The frame trace (`RX_VK_FRAME_TRACE=1`) has a new column, `acquire_cpu_ms`: the main thread's CPU time inside `game_phase_run`, the whole of the mod runtime's frame, read around the call in `host/nn_vi.c` (two thread-clock reads a frame, only while the frame is timed) and handed to the renderer as `MkwVkHost.main_thread_times`' fourth value (API version 82). - **What they showed** (Hyrule Field, below): the gap is the acquire phase; the hook sites on the main thread cost next to nothing (the ones with time there are the barrier fix's sleeps, which main has too). The phase is many small steps, none big: the settings host's step, the renderer status the HDR mod reads, the loader's manifest check, the timers, the input step, the UI's frame end, each 2 to 8 us. - **The cuts** (commit 2): the timers step walks only the mods that have timers (it copied the load order and made two lists for every running mod each frame); the load order is shared (`Rc`), so the steps that walk it take a count, not a copy; the Insert menu's fallback does nothing unless it shows or is wanted; the loader's check of the linked manifests walks the list it set, in order, with no look-up by id; the frame event's payload is made only for a listener; the game's moments make no listener list for an event nobody listens to; and one Rust function's handler around an empty core (widescreen's and sprint-walk's sites) takes the plain trampoline instead of the dispatcher: no chain loaded or walked, but still counted in the site's readers (its pointer tagged in `PLAIN`), so `remove_retired`/`remove_then` wait for a hook still in it, as they do for the dispatcher (commit 3). Read first: `game/crates/game-sites/src/cost.rs`, `chain.rs`'s `publish`, `api/src/services/time.rs`'s `timers_step`. ## Testing **Tested:** Linux (CachyOS 7.3.3), RTX 3090, NVIDIA 620.70.06. In the game, Hyrule Field (child), 1080p native, six measured runs of 60 s through `dev.py ab` (below): every system mod started, no fault, the frame trace's `acquire_cpu_ms` filled on this PR's side. Before the cuts, two runs with `HOS_FRAME_COST=1` logged their `frame cost:` lines every 10 s (the numbers in Summary). Checks: `cargo clippy -D warnings` and `cargo test` of game-sites, api, longshot-game and the widescreen, sprint-walk and shadows system mods; `tests/run_all.py --changed` (204 checks: one failed, `test_pacing_policy.py`, fixed by giving its fixture the thread clock, then passed with `test_frame_trace_waits.py`); the renderer compiled for Windows with llvm-mingw. The host's Windows compile (`check_host_compile.py`) compiled every unit but `host/nn_video.c`, which needs FFmpeg's headers this PC's setup does not give it (not a file this PR changes; `host/nn_vi.c` compiled). After the review fix and the rebase onto `mod-api` @ 75bcd270 (one build-mode queue job): clippy `-D warnings` and `cargo test` of game-sites (with `fake`), api and longshot-game, `tests/run_all.py --changed`, `scripts/shaders.py all` and the whole Windows host compile (`check_host_compile.py`, llvm-mingw, with FFmpeg's headers) all passed. game-sites' new test `a_lone_function_handler_removed_while_running_waits_for_it` fails without the readers' count and passes with it. game-sites' `retire` tests fail now and then under load, on `mod-api` too (5 runs in 25 there): not this PR's. **Still to test:** - Windows (any GPU): a frame trace run (`RX_VK_FRAME_TRACE=1`), expecting `acquire_cpu_ms` filled and below `main_cpu_ms`; `HOS_FRAME_COST=1` logs its `frame cost:` lines every 10 s (@Beanstalk run Hyrule Field with RX_VK_FRAME_TRACE=1 and HOS_FRAME_COST=1 and attach the log's frame cost lines) - The lab PC (RX 580): the same A/B as below, expecting the same direction (by hand) ## Measurements **Verdict:** the main thread is 0.09 ms a frame over `main` now (2.018 against 1.928 ms), of which 0.066 ms is the mod runtime's acquire phase. Average fps is within 1 % of `main` (139.2 against 138.0). The 1% low (125.4 against 117.0, -6.7 %) and p99 (7.98 against 8.55 ms, +7.1 %) are noisy and inconclusive: their runs spread from 80 to 126 fps. The cuts' own share was not measured apart (no `mod-api` side was run): from the counters' per-step numbers they save about 10 to 15 us a frame (the timers 3 to 4 us, the manifest check about 4, the fallback about 2, the load-order copies and the moments' lists a few). The gap is not closed: what is left is the many 1 to 8 us steps above, the settings host's step and the renderer status the HDR mod reads being the biggest (area 2 and area 3 change those). Setup: Linux, RTX 3090, NVIDIA 620.70.06; Hyrule Field (child), output 1920x1080, Render resolution 100 %, no upscaler, uncapped, V-Sync and frame generation off (`dev.py ab --options native1080.ini`, `HOS_FPS_MAX=1000`); A, B, A, B, A, B, 60 s each after the warm-up, the median of three. `main_cpu_ms` and `acquire_cpu_ms` are the frame trace's means over the measured frames. A is `main`'s own runtime at the fork point, unconfined as `main` runs (`HOS_SANDBOX=0`: `main`'s game cannot serve the control bridge inside the builder's sandbox); B is this PR's, confined by default, as a player runs it. These numbers are from before the rebase. They still hold: the rebase onto `mod-api` @ 75bcd270 brought in #2855 (rustfmt only), #2861 (where menu rows are placed: menu layout and settings listing) and #2881 (a mod's game language: loader, manifest and init-time code). None of them runs per frame in Hyrule Field with the menu closed. The review fix adds two atomics per hit on widescreen's and sprint-walk's sites. That is what the dispatcher counted before this PR, without the chain load and walk. The user accepted the fps gap on this area, so the runs were not repeated. | | Before: main @ 46291934 | After: this PR @ 946cf164 | |---|---|---| | fps | 139.2 [131.6-139.3] | 138.0 [131.9-138.5] | | 1% low fps | 125.4 [80.6-126.3] | 117.0 [85.5-124.8] | | median / p99 frame ms | 7.19 / 7.98 | 7.22 / 8.55 | | main thread CPU ms (`main_cpu_ms`) | 1.928 [1.911-2.100] | 2.018 [2.004-2.222] | | its acquire phase ms (`acquire_cpu_ms`) | (no column) | 0.066 [0.065-0.075] | The third pair was noisy on both sides (p99 12 ms); the 1% low's median on B is its second run's (117.0; 124.8 and 85.5 the others). Run folder: `~/.local/share/longshot-dev/runs/ab/20261130-003115-hos_frame_cost-hos_sandbox-hyrule-field`. `dev.py ab` gave no write-up (exit 3): the sides differ in the menu's rows `mod-api` adds and in the sandbox's switches, as every `main` against `mod-api` comparison does. The counters' run (B with `HOS_FRAME_COST=1`, before the cuts, both sides confined then): acquire phase 0.133 ms with the counters' clock reads; steps a frame: services 76 us, loader 38 (the native mods' frames 28, of which hdr 4.7), settings host 7.9, the manifest check 5.7, input 4.0, UI frame end 3.9, timers 3.9, the game's moments 3.7, the file watch 2.8, the menu fallback 2.3; sites on the main thread 52 us a frame, nearly all the barrier fix's sleeps (`barrier.sleepClaim`), which `main` has too. Folder: `...runs/ab/20261129-215249-hos_frame_cost-hyrule-field`. ## Risks - The plain trampoline for a lone function handler counts itself in the site's readers and loads the function again once in. A publish off plain clears `PLAIN`, and a hook that read the old slot goes on to the dispatcher. So a removal's grace still waits for it. The site's hits are not counted in the stats for it (as for an owner) unless `HOS_FRAME_COST=1`. - `main_thread_times` now writes four values: host and renderer change together (API version 82). - Nothing changes for a player: no setting, file or cache. ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. (into `mod-api`, on `mod-api@origin` 75bcd270) - [x] Tested on my own PC, in the game for a change the game runs, as Testing says. - [x] `mise run test` passes (any failure that also fails on `main` is named). (the whole `tests/run_all.py` on the head: 733 passed, 114 skipped, 1 failed: `test_lifter.py`'s `build-core` test `control::tests::the_socket_is_made_private_and_a_client_handed_over`, in the builder's control socket, which this PR does not touch; it fails the same way on `mod-api` @ 12f42db5, checked in #2868's run) - [x] Measured against `main`, or Measurements says why there is nothing to measure. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [x] A switch added or changed: it ships at the default the measurements chose, with its row in `gpu/vk/switches.def`. (`HOS_FRAME_COST`, a diagnostic, off) - [x] A check under `tests/` that reads changed source is updated, not weakened. (`tests/test_frame_trace_waits.py`: the new column) - [x] `MKWVK_API_VERSION` bumped (`MkwVkHost` or `MkwVkRenderer` in `gpu/vk/vk_api.h` changed). - [x] Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. - [x] Docs updated. (`docs/dev/reference/hooks.md`, `profiling.md`) - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_016o1k1SQVyAWsujjFVd8Wuc
The mod runtime adds about 0.17 ms of main-thread CPU a frame over main, and no path read explains it. To see where it
goes:

- HOS_FRAME_COST=1 (game_sites::cost): each named step of the acquire phase (the loader's, each native mod's frame,
  every services step) on the thread's CPU clock, and every hook site's hits and time, the main thread's lane apart
  from the other threads', a few "frame cost:" lines in the log every 10 s. The plain trampoline's sites (the engine's
  73 Rust callbacks) count their hits too while it is on; off, a step and a plain hit cost one relaxed load.
- The frame trace's acquire_cpu_ms: the main thread's CPU time in game_phase_run (host/nn_vi.c), counted while the
  frame is timed; MkwVkHost.main_thread_times gives it as its [3] (version 82).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
perf(game): the acquire phase's per-frame scans cut: timers, the load order, the menu's fallback, plain handlers
Some checks failed
PR description / Title and description (pull_request_target) Failing after 6s
cbd0742fe3
HOS_FRAME_COST put the mod runtime's main-thread cost over main in the acquire phase (Hyrule Field: 0.13 ms a frame
with the counters' own clock reads; the sites on the main thread next to nothing), spread over many small steps of 1 to
8 us. What the steps did with nothing to do:

- the timers step copied the load order and made two lists for every running mod, timers or none: now it walks only
  the mods that have timers, and returns at once when none has;
- the load order is shared (Rc): the steps that walk it while they call the mods take a count, not a copy of every
  id (the UI's flush and frame, the actors', the effects', the rules', the together step's);
- the Insert menu's fallback made ids and worked out which menu mod is down every frame: now only while it shows or
  is wanted;
- the check that the manifests linked against are the loader's walks the list it set in order, with no look-up by
  id for every mod each frame;
- the frame event's payload is made only when a script listens to frame or update, and the game's moments make no
  listener list for an event no script listens to;
- one Rust function's handler around an empty core (widescreen's and sprint-walk's sites) takes the plain trampoline,
  as an owner alone does, instead of the dispatcher with its readers' count: a function lives for the run.

After them the acquire phase takes 0.066 ms a frame (acquire_cpu_ms, counters off) and the main thread's CPU is 0.09 ms
over main's (2.018 against 1.928 ms, three interleaved runs each).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Owner
@review
BeanBot left a comment

Recommendation: Request changes. The plain-handler optimization breaks the hook removal API’s grace-period guarantee. The claimed performance gain is also unproven because the cuts were not measured against the pull request’s base.

The change adds optional frame-cost diagnostics and reduces several mod-runtime scans and allocations. The optimization makes hook retirement less safe, and its net effect on frame time has not been isolated.

Blocking (1): must change before merging.

  1. L1 game/crates/game-sites/src/chain.rs:485: A lone function handler now bypasses the readers count, so remove_retired can report that its grace period passed while that handler is still running. (more on the line) Do: Keep handlers covered by the retirement readers, or provide an equivalent grace period for plain-handler calls and test removal while a function handler is in flight.

Nits (1): optional.

  • L4: The verdict says FPS and frame times are within 1% of main, but the table does not support that claim for the 1% low or p99. When: The listed median 1% low falls from 125.4 to 117.0 FPS, about 6.7%, and p99 rises from 7.98 to 8.55 ms, about 7.1%; the runs are noisy. Do: Describe those results as noisy and inconclusive, and report the differences alongside the averages.

Testing before merging (2) (runs on the systems it can change; it doesn't hold the recommendation)

  • L2: The performance cuts have no measurement against their actual base, so their gain and effect on frame pacing are unknown. When: The reported comparison changes both the runtime branch and sandbox configuration; its 1% low and p99 also vary substantially between runs. It cannot attribute a gain to these cuts. Do: Run several interleaved, same-settings comparisons of cb37f5ab against this head in the target and a heavy area, reporting acquire CPU time, FPS, 1% lows and frame times.
  • L3: The new host timing and hook paths have not been exercised on the other supported Tier 1 systems. When: Windows uses a different thread CPU clock, and the changed hook paths and frame pacing also run on AMD systems and Steam Deck; the supplied game run covers Linux on NVIDIA only. Do: Run the frame trace and diagnostic switch on Windows, and exercise the changed runtime on Tier 1 AMD and Steam Deck hardware, checking for correct timing and frame pacing.

@fix can do L1 and L4.

Checks: Failing on this head, which is behind its base, where it passes: PR description / Title and description (pull_request_target). @rebase (or @fix) brings it up to date and runs it again; not held against it.

More: does it help, other systems, switches, what was read

Does it help: Unproven. The reported Linux RTX 3090 runs compare main with this PR, not mod-api with this PR: median FPS is 139.2 versus 138.0, and median 1% low is 125.4 versus 117.0. The author estimates the cuts save 10–15 µs per frame from instrumented step timings, but did not measure the cuts against their base.

Other systems: The hook and timing paths run on Windows and Linux and are independent of GPU vendor; frame pacing can nevertheless vary by system. The supplied run covers Linux on NVIDIA; Windows, AMD and Steam Deck results are still needed for the affected paths.

Switches: HOS_FRAME_COST is added as an off-by-default diagnostic switch, with a switches.def row. Off is appropriate for its instrumentation overhead.

Reviewed: cbd0742fe3 against cb37f5ab8a: Read the repository rules, PR template, standards, commit messages and diff; read the new cost module, timer service, hook chain and statistics code, and inspected the relevant runtime, host clock and retirement callers. Other changed files and surrounding code were inspected through the diff and targeted searches, not read in full. The requested review-checklist file and sibling Tooling checkout were absent. Recorded runs were read from the PR description; no run files were available.; nothing run (a code review).

Checked and fine:

  • Both commits include AI-assistance trailers.
  • The renderer API version is bumped for the expanded host callback.
  • The timer optimization preserves the rule that timers created during a timer round wait until the next frame.
  • No game-derived outputs or generated binaries appear among the changed files.

Testing: No code or tests were run, as requested. The PR reports Linux game runs and changed checks; Windows game testing and the remaining hardware runs are outstanding.

Overlaps and merge order: Not checked; network access is closed.


Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.

**Recommendation: Request changes.** The plain-handler optimization breaks the hook removal API’s grace-period guarantee. The claimed performance gain is also unproven because the cuts were not measured against the pull request’s base. The change adds optional frame-cost diagnostics and reduces several mod-runtime scans and allocations. The optimization makes hook retirement less safe, and its net effect on frame time has not been isolated. **Blocking (1)**: must change before merging. 1. **L1** `game/crates/game-sites/src/chain.rs:485`: A lone function handler now bypasses the readers count, so remove_retired can report that its grace period passed while that handler is still running. (more on the line) **Do:** Keep handlers covered by the retirement readers, or provide an equivalent grace period for plain-handler calls and test removal while a function handler is in flight. **Nits (1)**: optional. - **L4**: The verdict says FPS and frame times are within 1% of main, but the table does not support that claim for the 1% low or p99. *When:* The listed median 1% low falls from 125.4 to 117.0 FPS, about 6.7%, and p99 rises from 7.98 to 8.55 ms, about 7.1%; the runs are noisy. **Do:** Describe those results as noisy and inconclusive, and report the differences alongside the averages. **Testing before merging (2)** (runs on the systems it can change; it doesn't hold the recommendation) - **L2**: The performance cuts have no measurement against their actual base, so their gain and effect on frame pacing are unknown. *When:* The reported comparison changes both the runtime branch and sandbox configuration; its 1% low and p99 also vary substantially between runs. It cannot attribute a gain to these cuts. **Do:** Run several interleaved, same-settings comparisons of cb37f5ab against this head in the target and a heavy area, reporting acquire CPU time, FPS, 1% lows and frame times. - **L3**: The new host timing and hook paths have not been exercised on the other supported Tier 1 systems. *When:* Windows uses a different thread CPU clock, and the changed hook paths and frame pacing also run on AMD systems and Steam Deck; the supplied game run covers Linux on NVIDIA only. **Do:** Run the frame trace and diagnostic switch on Windows, and exercise the changed runtime on Tier 1 AMD and Steam Deck hardware, checking for correct timing and frame pacing. `@fix` can do L1 and L4. **Checks:** Failing on this head, which is behind its base, where it passes: `PR description / Title and description (pull_request_target)`. `@rebase` (or `@fix`) brings it up to date and runs it again; not held against it. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Unproven. The reported Linux RTX 3090 runs compare main with this PR, not mod-api with this PR: median FPS is 139.2 versus 138.0, and median 1% low is 125.4 versus 117.0. The author estimates the cuts save 10–15 µs per frame from instrumented step timings, but did not measure the cuts against their base. **Other systems:** The hook and timing paths run on Windows and Linux and are independent of GPU vendor; frame pacing can nevertheless vary by system. The supplied run covers Linux on NVIDIA; Windows, AMD and Steam Deck results are still needed for the affected paths. **Switches:** HOS_FRAME_COST is added as an off-by-default diagnostic switch, with a switches.def row. Off is appropriate for its instrumentation overhead. **Reviewed:** cbd0742fe322 against cb37f5ab8a63: Read the repository rules, PR template, standards, commit messages and diff; read the new cost module, timer service, hook chain and statistics code, and inspected the relevant runtime, host clock and retirement callers. Other changed files and surrounding code were inspected through the diff and targeted searches, not read in full. The requested review-checklist file and sibling Tooling checkout were absent. Recorded runs were read from the PR description; no run files were available.; nothing run (a code review). **Checked and fine:** - Both commits include AI-assistance trailers. - The renderer API version is bumped for the expanded host callback. - The timer optimization preserves the rule that timers created during a timer round wait until the next frame. - No game-derived outputs or generated binaries appear among the changed files. **Testing:** No code or tests were run, as requested. The PR reports Linux game runs and changed checks; Windows game testing and the remaining hardware runs are outstanding. **Overlaps and merge order:** Not checked; network access is closed. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.</sub>
@ -474,0 +482,4 @@
// lives for the run: a C function, a `SiteFn`, never a closure)
let plain_owner = match (wraps.as_slice(), core.as_slice()) {
([], [only]) if only.answers => Some(only.handler.clone()),
([h @ Handler::Fn(_)], []) => Some(h.clone()),
Member

L1 (blocking): A lone function handler now bypasses the readers count, so remove_retired can report that its grace period passed while that handler is still running.

When: A thread enters a Handler::Fn through the plain trampoline while another removes it with remove_retired. Reclaim sees no dispatcher readers and marks the guard passed, allowing the caller to release state the function uses while the first thread still accesses it.

Do: Keep handlers covered by the retirement readers, or provide an equivalent grace period for plain-handler calls and test removal while a function handler is in flight.

**L1** (blocking): A lone function handler now bypasses the readers count, so remove_retired can report that its grace period passed while that handler is still running. *When:* A thread enters a Handler::Fn through the plain trampoline while another removes it with remove_retired. Reclaim sees no dispatcher readers and marks the guard passed, allowing the caller to release state the function uses while the first thread still accesses it. **Do:** Keep handlers covered by the retirement readers, or provide an equivalent grace period for plain-handler calls and test removal while a function handler is in flight.
HumanBean force-pushed cleanup/area7-frame-cost from cbd0742fe3
Some checks failed
PR description / Title and description (pull_request_target) Failing after 6s
to 899cc67bdb
All checks were successful
PR description / Title and description (pull_request_target) Successful in 6s
2026-11-30 17:44:34 +00:00
Compare
Author
Owner

L1 fixed (899cc67b): a lone Handler::Fn on the plain trampoline is now counted in the site's readers (tagged in PLAIN, PLAIN reloaded once in, cleared on any publish off plain, null falls to the dispatcher), so remove_retired/remove_then wait for it again; new test removes the handler from inside it and fails without the count.
L4: Measurements now call the 1% low and p99 noisy and inconclusive and give the differences. L2: not re-measured — the user accepted this area's fps gap; the rebase onto mod-api @ 75bcd270 brought in nothing per frame (Measurements says why). L3 stays in Still to test (Windows via Beanstalk, the lab by hand).

L1 fixed (899cc67b): a lone `Handler::Fn` on the plain trampoline is now counted in the site's readers (tagged in `PLAIN`, PLAIN reloaded once in, cleared on any publish off plain, null falls to the dispatcher), so `remove_retired`/`remove_then` wait for it again; new test removes the handler from inside it and fails without the count. L4: Measurements now call the 1% low and p99 noisy and inconclusive and give the differences. L2: not re-measured — the user accepted this area's fps gap; the rebase onto mod-api @ 75bcd270 brought in nothing per frame (Measurements says why). L3 stays in Still to test (Windows via Beanstalk, the lab by hand).
Author
Owner

Landed on mod-api as e8f8ca8c (one commit), after its review fixes and one batched build + game run of all six cleanup areas together. mod-api work now goes straight onto the branch once self-reviewed.

Landed on mod-api as e8f8ca8c (one commit), after its review fixes and one batched build + game run of all six cleanup areas together. mod-api work now goes straight onto the branch once self-reviewed.
HumanBean closed this pull request 2026-11-30 22:34:16 +00:00
All checks were successful
PR description / Title and description (pull_request_target) Successful in 6s

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MagicBeanDev/Longshot!2880
No description provided.