WIP: perf(nvn): a call of several recordings makes room for all of them at once (HOS_NVN_CALL_RESERVE=0 to disable) #2023

Draft
siantm wants to merge 5 commits from siantm/Longshot:perf/nvn-call-reserve into main
Contributor

Summary

nvnCommandBufferCallCommands and nvnCommandBufferCopyCommands copy each called recording into the caller's
recording segment. They did it one recording at a time: each called recording that did not fit grew the segment by
doubling, a copy of everything the segment held at each step, so a call of several large recordings could grow (and
copy) the segment more than once.

With this, a call of 2 to 64 recordings reads the game's array of handles once, checks all of the handles and sizes
them (called_size), makes room for all of their records once (cmd_reserve_rec), then checks each handle again just
before its copy, as main does, and copies it (inline_recording, whose reserve returns at once: the room is there). The
check-to-copy window is main's own; a recording the game releases while the room is made stops the call at its second
check, as on main, and released copies are freed as on main. A call whose recordings come to more than CMD_SEG_MAX
(4 GiB), and any segment growth past it, stops with the NVN diagnostic instead of wrapping a size. The bytes recorded
and the command memory counts are the same as one at a time. A handle that is not live still stops the game, now
before any of the call is copied, which the game does not see. The result expected: fewer segment growths and fewer
bytes copied by them in calls of several recordings.

Both ways, CallCommands and CopyCommands check their count and array in one place (call_handles: a count of 0 reads
nothing, a negative count or a count with no array stops with the diagnostic), read each handle once, and the
HOS_NVN_WATCH_DRAW watch's table and watched command buffer are written and read atomically. The recordings' log line
(every 50,000 recordings) now also counts the segments' growths, the bytes they copied and the calls given their room
at once, so the in-game A/B can compare them.

The switch: HOS_NVN_CALL_RESERVE (new, a kill switch, bool, its row in gpu/vk/switches.def), on (unset), the
value this change proposes; =0 (or false, off, no) is main's code, one recording at a time, the segment growing
for each that does not fit. It is read at the first call of several recordings and cached; threads making that call
together may each read the variable, and all keep the first answer stored. An empty value in longshot_env.txt on
Windows removes the variable (on, as unset); =0 is off everywhere.

From 3e8a2abd on exp/x86-asm-sync, where it was the second half of HOS_NVN_SEG_PEAK; the first half (a grown
segment growing at once to the command buffer's recent peak) is not part of this. Prior work: #1812 (GummiNaomi)
prefetched the next handle in the same CallCommands / CopyCommands loops and started each first segment at a size
hint; its author closed it unmerged, having measured no change at 4 or 16 cores. This one does neither: it sizes the
caller's segment once for the whole call.

Read first: call_reserve_on, inline_recordings and call_handles in host/nvn_native.c, then
tests/test_nvn_call_reserve.py.

Testing

Tested: Windows 11, i7-9700, RTX 4060, the builder's llvm-mingw clang 23; head 39fe40de on main 9dd41326 (rebased from b62932a9, git range-diff "=" for every commit; main's move touched none of this PR's files). Queue jobs of this PC's job queue, every check in a hidden console with --timeout 1200: fb-2023-l9 (light): tests/test_nvn_call_reserve.py at the test commit eb4d64f6 fails on the code before the fix (the switch's first read answers 0 where 1 is expected, and the run stops there); at the head, tests/run_all.py --strict --exact tests/test_nvn_call_reserve.py tests/test_switch_table.py tests/test_recording_log_handoff.py tests/test_host_alloc_wait.py: 4 passed; host/nvn_native.c compiles with the game build's own command (-fsyntax-only). fb-2023-h9 (build): every check tests/run_all.py --strict --changed 9dd41326 picks: 52 checks, 40 passed, 9 failed, 3 skipped (Linux-only); the 9 fail on main @ 9dd41326 too, run from a main worktree in the same job: tests/test_crash_dialog.py, tests/test_dev_ab.py, tests/test_dev_packs.py, tests/test_frame_overlap.py, tests/test_host_guest_writes.py, tests/test_linux_pressure.py, tests/test_present_queue_default.py, tests/test_target_reuse_memory.py, tests/test_vk_occlusion_queries.py. Not run here: Linux, the whole suite and lint.

In the game on this PC: two sittings of HOS_NVN_CALL_RESERVE=0 against unset (on) in one runtime of this head,
Kokiri Forest, 16 runs each, and a Market pair against main in each (Measurements); no not a live recording line, FATAL, device lost
or Vulkan error in any run. With it on, the recordings' line counted about 12,700 calls of several recordings given
their room at once every 100,000 recordings in play, none with =0.

Still to test:

  • Windows 11, i7-9700, RTX 4060 (this PC): Castle Town Market walking through the crowd, main @ 9dd41326, this PR unset
    and this PR with HOS_NVN_CALL_RESERVE=0, warmed, interleaved, at least three runs each, expecting no not a live recording line, no FATAL, the same picture all three ways, and average fps, 1% lows, median and p99 frame times and
    peak host memory unset at least those of the other two (by hand)
  • Linux NVIDIA and AMD, Windows AMD and Intel, Steam Deck: Kokiri Forest and Castle Town Market, three minutes each on
    main, on this PR unset and on this PR with HOS_NVN_CALL_RESERVE=0, warmed and interleaved, expecting no not a live recording line, no FATAL and the same picture (the test farm: linux+nvidia, linux+amd, windows+amd, windows+intel,
    steamdeck: Kokiri Forest and Castle Town Market three minutes, main, HOS_NVN_CALL_RESERVE unset and =0, warmed and
    interleaved, the log with its live copies (MB), frame times, peak host memory and a screenshot)
  • Linux: build the host and run python3 -I -B tests/test_nvn_call_reserve.py --cc gcc, expecting PASS (by hand)
  • A PC with pre-commit and ruff installed: mise run test and mise run lint at this head, expecting every failure to
    fail on main too and lint to pass (by hand; neither tool is installed on this PC)

Measurements

Verdict: in two sittings on this PC (Kokiri Forest, CPU-paced, 8 runs a side in each; In play below), the change
copies fewer bytes, shown twice, and no time is shown. With it on, the segments' growths copied 13 % fewer bytes: 426
against 373 MB every 100,000 recordings in play in the first sitting and 432 against 375 in the second, every run apart
in both (p = 0.0002 each); pooled 57 MB fewer every 100,000 recordings (95 % interval 52 to 64), a few tens of KB a frame
at the 50 to 110 recordings a frame this scene makes. The fewer growths it was expected to bring did not come: 3,390
against 3,389 and 3,435 against 3,443 every 100,000 recordings (pooled +0.5 %, p = 0.37). No line times the copies, and
nothing timed is shown: the first sitting's leans for it (the game's own code -1.2 %, draw -3.3 %) are gone in the second
(9.71 against 9.72 ms, 2.77 against 2.77 ms); pooled, the game's own code -0.8 % (p = 0.19), the replay's submit -1.5 %
(p = 0.15), median frame time -0.8 % (p = 0.29). HOS_NVN_CALL_RESERVE ships on, the value this change proposes. On the branch, HOS_NVN_SEG_PEAK as a whole (this and the peak growth) measured no difference in
play (2cc8489c); its micro-benchmark (3e8a2abd) is mostly the peak growth, which is not here, so it is not quoted.

Baseline: this PR with HOS_NVN_CALL_RESERVE=0 (one recording at a time, main's code) in the same runtime as unset:
one build, the switch the only difference; and main @ 9dd41326 for the Market pair.

In play (held job fb-g2023, 04:38 to 05:23 UTC on 2026-11-24): one runtime of this head 39fe40de on main 9dd41326,
Windows 11, i7-9700, RTX 4060; Threaded rendering at its default; Kokiri Forest from the scene's save, 60 s, the output
at 800x600 (CPU-paced, on an 800x600 desktop at 30 Hz), the GPU cooled to 70 C before each run; a warm-up a side, then
8 runs a side interleaved (off on on off, four times); all 16 counted, every one light, at create. The recordings'
figures are from its line (every 50,000 recordings), in steady play (after the last load); p from an exact swap test of
the 8 runs a side.

a side: median (range), Kokiri Forest Before: this PR @ 39fe40de, HOS_NVN_CALL_RESERVE=0, 8 runs After: this PR @ 39fe40de, unset (on), 8 runs change of the means, p (swap test)
segments' growths, every 100,000 recordings in play 3,390 (3,264 to 3,482) 3,389 (3,313 to 3,454) -0.1 %, 0.95
MB copied by them, every 100,000 recordings in play 426 (408 to 437) 373 (334 to 381) -13 %, 0.0002
the same over the whole run 320 (294 to 325) 280 (240 to 287) -13 %, 0.0002
calls given their room at once, every 100,000 recordings in play 0 12,655 (12,472 to 12,905)
live copies at the run's end 41,977 (41,667 to 45,542) 41,966 (41,238 to 44,085) -1.3 %, 0.34
calm-stretch game_ms (the game's own code) 10.30 (10.10 to 10.69) 10.16 (9.96 to 10.57) -1.2 %, 0.21
main thread blocked, ms a frame 8.44 (8.28 to 8.71) 8.24 (8.07 to 8.79) -1.9 %, 0.12
draw (frame trace), ms a frame 2.98 (2.79 to 3.16) 2.90 (2.78 to 3.08) -3.3 %, 0.10
a frame's replay time (ms): submit 6.14 (5.73 to 6.37) 5.90 (5.68 to 6.30) -3.3 %, 0.081
median frame time, ms 11.05 (10.78 to 11.45) 10.79 (10.64 to 11.49) -1.7 %, 0.16
p99 frame time, ms 20.7 (16.8 to 40.9) 17.3 (16.2 to 91.2) +19 %, 0.86
frames of 50 ms or more, all runs 33 83 0.80

The frames of 50 ms or more came by run: 12, 10, 3, 3, 3, 2, 0 and 0 with =0, and 64, 8, 4, 2, 2, 1, 1 and 1 unset.
The 64 are one run's, and its long frames in the last minute were the game's own thread (about 117 ms of its code and
121 ms blocked in each, the renderer 3 ms). Not shown either way.

The Market pair (60 s, one run a side): main @ 9dd41326's run took place while this PC was at its commit limit (50.9 of
52.2 GB committed), so the pair is spoiled and not read. This head's run (unset) had no not a live recording line and
no FATAL, and counted 78,308 calls given their room at once by its last line.

In play, the second sitting (held job fb-g2023b, chain 21, ended 08:40 UTC on 2026-11-24): the same script, runtime
and settings as the first, on the same 800x600 desktop; all 16 counted, every one light, at create; no load marker, no
run held, and no commit-limit line in any run.

a side: median (range), Kokiri Forest Before: this PR @ 39fe40de, HOS_NVN_CALL_RESERVE=0, 8 runs After: this PR @ 39fe40de, unset (on), 8 runs change of the means, p (swap test)
segments' growths, every 100,000 recordings in play 3,435 (3,348 to 3,459) 3,443 (3,391 to 3,553) +1.0 %, 0.15
MB copied by them, every 100,000 recordings in play 432 (422 to 437) 375 (362 to 381) -13.5 %, 0.0002
the same over the whole run 328 (299 to 331) 277 (254 to 287) -14.7 %, 0.0002
calls given their room at once, every 100,000 recordings in play 0 12,849 (12,663 to 13,257)
live copies at the run's end 42,459 (41,080 to 53,421) 44,246 (41,753 to 51,408) +1.4 %, 0.75
calm-stretch game_ms (the game's own code) 9.71 (9.61 to 10.02) 9.72 (9.48 to 9.95) -0.4 %, 0.62
main thread blocked, ms a frame 8.07 (8.00 to 8.23) 8.07 (7.95 to 8.30) +0.0 %, 0.98
draw (frame trace), ms a frame 2.77 (2.64 to 2.80) 2.78 (2.74 to 2.89) +1.2 %, 0.25
a frame's replay time (ms): submit 5.71 (5.52 to 5.74) 5.69 (5.59 to 5.85) +0.4 %, 0.57
median frame time, ms 10.44 (10.25 to 10.61) 10.42 (10.27 to 10.79) +0.3 %, 0.73
p99 frame time, ms 14.2 (13.6 to 26.5) 13.7 (13.3 to 29.7) -6.6 %, 0.62
frames of 50 ms or more, all runs 3 6 1.00

The two sittings pooled (labels swapped within a sitting only, 20,000 times; intervals by resampling runs within each
sitting and side): MB copied every 100,000 recordings in play -57.3 (-13.4 %, 95 % interval -63.9 to -51.7, p < 0.0001);
growths +16 (+0.5 %, -15 to +50, p = 0.37); calm-stretch game_ms -0.08 ms (-0.8 %, -0.19 to +0.03, p = 0.19); main thread
blocked -0.9 % (p = 0.17); median frame time -0.08 ms (-0.8 %, -0.21 to +0.06, p = 0.29).

The Market pair of this sitting (60 s, one run a side, a reference; sound this time, the PC at 46.6 of 49.2 GB committed at
its peak): main @ 9dd41326 against this head unset, calm-stretch game_ms 12.80 against 12.55, p99 44.2 against 24.0 ms,
23 against 14 frames of 50 ms or more; not read either way.

Risks

What could break: a call's records copied wrong or counted wrong would show as wrong or missing draws in any scene, or
wrong heap sizes the game computes from the command memory counts; the test compares every recording's bytes and counts
with the switch on and off over 3,000 recordings, and a call's bytes and counts against the records as written. The
check-to-copy window is main's own, no wider: each handle is checked again just before its copy, so a recording released
while the room is made stops the call as on main (the pin case), and nothing holds released copies: they are freed
as on main. Its cost: one more lock-free check of each handle a call, and the room made with the sizes of the first
check. Turn it off with HOS_NVN_CALL_RESERVE=0. Either way, what changes from main: a call with a negative count or a
count but no array stops with the NVN diagnostic (it read memory at address 0 before), a recording segment past 4 GiB
stops with it, the watch is atomic and the log line has three more counts. Host code: the runtime is rebuilt; nothing
changes for players' saves, options or caches.

Overlap: #1780 (snaildev99's, WIP) also changes the end-of-recording log line in nvnCommandBufferEndRecording
(host/nvn_native.c); the two conflict there and nowhere else. Whichever is merged first goes first and the other
rebases onto it: this one, if #1780 is first.

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit.
  • 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).
  • 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.
  • Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths.
  • 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.
## Summary `nvnCommandBufferCallCommands` and `nvnCommandBufferCopyCommands` copy each called recording into the caller's recording segment. They did it one recording at a time: each called recording that did not fit grew the segment by doubling, a copy of everything the segment held at each step, so a call of several large recordings could grow (and copy) the segment more than once. With this, a call of 2 to 64 recordings reads the game's array of handles once, checks all of the handles and sizes them (`called_size`), makes room for all of their records once (`cmd_reserve_rec`), then checks each handle again just before its copy, as main does, and copies it (`inline_recording`, whose reserve returns at once: the room is there). The check-to-copy window is main's own; a recording the game releases while the room is made stops the call at its second check, as on main, and released copies are freed as on main. A call whose recordings come to more than `CMD_SEG_MAX` (4 GiB), and any segment growth past it, stops with the NVN diagnostic instead of wrapping a size. The bytes recorded and the command memory counts are the same as one at a time. A handle that is not live still stops the game, now before any of the call is copied, which the game does not see. The result expected: fewer segment growths and fewer bytes copied by them in calls of several recordings. Both ways, CallCommands and CopyCommands check their count and array in one place (`call_handles`: a count of 0 reads nothing, a negative count or a count with no array stops with the diagnostic), read each handle once, and the `HOS_NVN_WATCH_DRAW` watch's table and watched command buffer are written and read atomically. The recordings' log line (every 50,000 recordings) now also counts the segments' growths, the bytes they copied and the calls given their room at once, so the in-game A/B can compare them. The switch: `HOS_NVN_CALL_RESERVE` (new, a kill switch, bool, its row in `gpu/vk/switches.def`), **on** (unset), the value this change proposes; `=0` (or `false`, `off`, `no`) is main's code, one recording at a time, the segment growing for each that does not fit. It is read at the first call of several recordings and cached; threads making that call together may each read the variable, and all keep the first answer stored. An empty value in `longshot_env.txt` on Windows removes the variable (on, as unset); `=0` is off everywhere. From 3e8a2abd on `exp/x86-asm-sync`, where it was the second half of `HOS_NVN_SEG_PEAK`; the first half (a grown segment growing at once to the command buffer's recent peak) is not part of this. Prior work: #1812 (GummiNaomi) prefetched the next handle in the same CallCommands / CopyCommands loops and started each first segment at a size hint; its author closed it unmerged, having measured no change at 4 or 16 cores. This one does neither: it sizes the caller's segment once for the whole call. Read first: `call_reserve_on`, `inline_recordings` and `call_handles` in `host/nvn_native.c`, then `tests/test_nvn_call_reserve.py`. ## Testing **Tested:** Windows 11, i7-9700, RTX 4060, the builder's llvm-mingw clang 23; head `39fe40de` on main `9dd41326` (rebased from `b62932a9`, `git range-diff` "=" for every commit; main's move touched none of this PR's files). Queue jobs of this PC's job queue, every check in a hidden console with `--timeout 1200`: `fb-2023-l9` (light): `tests/test_nvn_call_reserve.py` at the test commit `eb4d64f6` fails on the code before the fix (the switch's first read answers 0 where 1 is expected, and the run stops there); at the head, `tests/run_all.py --strict --exact tests/test_nvn_call_reserve.py tests/test_switch_table.py tests/test_recording_log_handoff.py tests/test_host_alloc_wait.py`: 4 passed; `host/nvn_native.c` compiles with the game build's own command (`-fsyntax-only`). `fb-2023-h9` (build): every check `tests/run_all.py --strict --changed 9dd41326` picks: 52 checks, 40 passed, 9 failed, 3 skipped (Linux-only); the 9 fail on main @ 9dd41326 too, run from a main worktree in the same job: `tests/test_crash_dialog.py`, `tests/test_dev_ab.py`, `tests/test_dev_packs.py`, `tests/test_frame_overlap.py`, `tests/test_host_guest_writes.py`, `tests/test_linux_pressure.py`, `tests/test_present_queue_default.py`, `tests/test_target_reuse_memory.py`, `tests/test_vk_occlusion_queries.py`. Not run here: Linux, the whole suite and lint. **In the game on this PC:** two sittings of `HOS_NVN_CALL_RESERVE=0` against unset (on) in one runtime of this head, Kokiri Forest, 16 runs each, and a Market pair against main in each (Measurements); no `not a live recording` line, FATAL, device lost or Vulkan error in any run. With it on, the recordings' line counted about 12,700 calls of several recordings given their room at once every 100,000 recordings in play, none with `=0`. **Still to test:** - Windows 11, i7-9700, RTX 4060 (this PC): Castle Town Market walking through the crowd, main @ 9dd41326, this PR unset and this PR with `HOS_NVN_CALL_RESERVE=0`, warmed, interleaved, at least three runs each, expecting no `not a live recording` line, no FATAL, the same picture all three ways, and average fps, 1% lows, median and p99 frame times and peak host memory unset at least those of the other two (by hand) - Linux NVIDIA and AMD, Windows AMD and Intel, Steam Deck: Kokiri Forest and Castle Town Market, three minutes each on main, on this PR unset and on this PR with `HOS_NVN_CALL_RESERVE=0`, warmed and interleaved, expecting no `not a live recording` line, no FATAL and the same picture (the test farm: linux+nvidia, linux+amd, windows+amd, windows+intel, steamdeck: Kokiri Forest and Castle Town Market three minutes, main, HOS_NVN_CALL_RESERVE unset and =0, warmed and interleaved, the log with its live copies (MB), frame times, peak host memory and a screenshot) - Linux: build the host and run `python3 -I -B tests/test_nvn_call_reserve.py --cc gcc`, expecting PASS (by hand) - A PC with pre-commit and ruff installed: `mise run test` and `mise run lint` at this head, expecting every failure to fail on main too and lint to pass (by hand; neither tool is installed on this PC) ## Measurements **Verdict:** in two sittings on this PC (Kokiri Forest, CPU-paced, 8 runs a side in each; In play below), the change copies fewer bytes, shown twice, and no time is shown. With it on, the segments' growths copied 13 % fewer bytes: 426 against 373 MB every 100,000 recordings in play in the first sitting and 432 against 375 in the second, every run apart in both (p = 0.0002 each); pooled 57 MB fewer every 100,000 recordings (95 % interval 52 to 64), a few tens of KB a frame at the 50 to 110 recordings a frame this scene makes. The fewer growths it was expected to bring did not come: 3,390 against 3,389 and 3,435 against 3,443 every 100,000 recordings (pooled +0.5 %, p = 0.37). No line times the copies, and nothing timed is shown: the first sitting's leans for it (the game's own code -1.2 %, draw -3.3 %) are gone in the second (9.71 against 9.72 ms, 2.77 against 2.77 ms); pooled, the game's own code -0.8 % (p = 0.19), the replay's submit -1.5 % (p = 0.15), median frame time -0.8 % (p = 0.29). `HOS_NVN_CALL_RESERVE` ships on, the value this change proposes. On the branch, `HOS_NVN_SEG_PEAK` as a whole (this and the peak growth) measured no difference in play (2cc8489c); its micro-benchmark (3e8a2abd) is mostly the peak growth, which is not here, so it is not quoted. **Baseline:** this PR with `HOS_NVN_CALL_RESERVE=0` (one recording at a time, main's code) in the same runtime as unset: one build, the switch the only difference; and main @ 9dd41326 for the Market pair. **In play** (held job `fb-g2023`, 04:38 to 05:23 UTC on 2026-11-24): one runtime of this head 39fe40de on main 9dd41326, Windows 11, i7-9700, RTX 4060; Threaded rendering at its default; Kokiri Forest from the scene's save, 60 s, the output at 800x600 (CPU-paced, on an 800x600 desktop at 30 Hz), the GPU cooled to 70 C before each run; a warm-up a side, then 8 runs a side interleaved (off on on off, four times); all 16 counted, every one light, at create. The recordings' figures are from its line (every 50,000 recordings), in steady play (after the last load); p from an exact swap test of the 8 runs a side. | a side: median (range), Kokiri Forest | Before: this PR @ 39fe40de, `HOS_NVN_CALL_RESERVE=0`, 8 runs | After: this PR @ 39fe40de, unset (on), 8 runs | change of the means, p (swap test) | |---|---|---|---| | segments' growths, every 100,000 recordings in play | 3,390 (3,264 to 3,482) | 3,389 (3,313 to 3,454) | -0.1 %, 0.95 | | MB copied by them, every 100,000 recordings in play | 426 (408 to 437) | 373 (334 to 381) | -13 %, 0.0002 | | the same over the whole run | 320 (294 to 325) | 280 (240 to 287) | -13 %, 0.0002 | | calls given their room at once, every 100,000 recordings in play | 0 | 12,655 (12,472 to 12,905) | | | live copies at the run's end | 41,977 (41,667 to 45,542) | 41,966 (41,238 to 44,085) | -1.3 %, 0.34 | | calm-stretch game_ms (the game's own code) | 10.30 (10.10 to 10.69) | 10.16 (9.96 to 10.57) | -1.2 %, 0.21 | | main thread blocked, ms a frame | 8.44 (8.28 to 8.71) | 8.24 (8.07 to 8.79) | -1.9 %, 0.12 | | draw (frame trace), ms a frame | 2.98 (2.79 to 3.16) | 2.90 (2.78 to 3.08) | -3.3 %, 0.10 | | `a frame's replay time (ms)`: submit | 6.14 (5.73 to 6.37) | 5.90 (5.68 to 6.30) | -3.3 %, 0.081 | | median frame time, ms | 11.05 (10.78 to 11.45) | 10.79 (10.64 to 11.49) | -1.7 %, 0.16 | | p99 frame time, ms | 20.7 (16.8 to 40.9) | 17.3 (16.2 to 91.2) | +19 %, 0.86 | | frames of 50 ms or more, all runs | 33 | 83 | 0.80 | The frames of 50 ms or more came by run: 12, 10, 3, 3, 3, 2, 0 and 0 with `=0`, and 64, 8, 4, 2, 2, 1, 1 and 1 unset. The 64 are one run's, and its long frames in the last minute were the game's own thread (about 117 ms of its code and 121 ms blocked in each, the renderer 3 ms). Not shown either way. The Market pair (60 s, one run a side): main @ 9dd41326's run took place while this PC was at its commit limit (50.9 of 52.2 GB committed), so the pair is spoiled and not read. This head's run (unset) had no `not a live recording` line and no FATAL, and counted 78,308 calls given their room at once by its last line. **In play, the second sitting** (held job `fb-g2023b`, chain 21, ended 08:40 UTC on 2026-11-24): the same script, runtime and settings as the first, on the same 800x600 desktop; all 16 counted, every one light, at create; no load marker, no run held, and no commit-limit line in any run. | a side: median (range), Kokiri Forest | Before: this PR @ 39fe40de, `HOS_NVN_CALL_RESERVE=0`, 8 runs | After: this PR @ 39fe40de, unset (on), 8 runs | change of the means, p (swap test) | |---|---|---|---| | segments' growths, every 100,000 recordings in play | 3,435 (3,348 to 3,459) | 3,443 (3,391 to 3,553) | +1.0 %, 0.15 | | MB copied by them, every 100,000 recordings in play | 432 (422 to 437) | 375 (362 to 381) | -13.5 %, 0.0002 | | the same over the whole run | 328 (299 to 331) | 277 (254 to 287) | -14.7 %, 0.0002 | | calls given their room at once, every 100,000 recordings in play | 0 | 12,849 (12,663 to 13,257) | | | live copies at the run's end | 42,459 (41,080 to 53,421) | 44,246 (41,753 to 51,408) | +1.4 %, 0.75 | | calm-stretch game_ms (the game's own code) | 9.71 (9.61 to 10.02) | 9.72 (9.48 to 9.95) | -0.4 %, 0.62 | | main thread blocked, ms a frame | 8.07 (8.00 to 8.23) | 8.07 (7.95 to 8.30) | +0.0 %, 0.98 | | draw (frame trace), ms a frame | 2.77 (2.64 to 2.80) | 2.78 (2.74 to 2.89) | +1.2 %, 0.25 | | `a frame's replay time (ms)`: submit | 5.71 (5.52 to 5.74) | 5.69 (5.59 to 5.85) | +0.4 %, 0.57 | | median frame time, ms | 10.44 (10.25 to 10.61) | 10.42 (10.27 to 10.79) | +0.3 %, 0.73 | | p99 frame time, ms | 14.2 (13.6 to 26.5) | 13.7 (13.3 to 29.7) | -6.6 %, 0.62 | | frames of 50 ms or more, all runs | 3 | 6 | 1.00 | The two sittings pooled (labels swapped within a sitting only, 20,000 times; intervals by resampling runs within each sitting and side): MB copied every 100,000 recordings in play -57.3 (-13.4 %, 95 % interval -63.9 to -51.7, p < 0.0001); growths +16 (+0.5 %, -15 to +50, p = 0.37); calm-stretch game_ms -0.08 ms (-0.8 %, -0.19 to +0.03, p = 0.19); main thread blocked -0.9 % (p = 0.17); median frame time -0.08 ms (-0.8 %, -0.21 to +0.06, p = 0.29). The Market pair of this sitting (60 s, one run a side, a reference; sound this time, the PC at 46.6 of 49.2 GB committed at its peak): main @ 9dd41326 against this head unset, calm-stretch game_ms 12.80 against 12.55, p99 44.2 against 24.0 ms, 23 against 14 frames of 50 ms or more; not read either way. ## Risks What could break: a call's records copied wrong or counted wrong would show as wrong or missing draws in any scene, or wrong heap sizes the game computes from the command memory counts; the test compares every recording's bytes and counts with the switch on and off over 3,000 recordings, and a call's bytes and counts against the records as written. The check-to-copy window is main's own, no wider: each handle is checked again just before its copy, so a recording released while the room is made stops the call as on main (the `pin` case), and nothing holds released copies: they are freed as on main. Its cost: one more lock-free check of each handle a call, and the room made with the sizes of the first check. Turn it off with `HOS_NVN_CALL_RESERVE=0`. Either way, what changes from main: a call with a negative count or a count but no array stops with the NVN diagnostic (it read memory at address 0 before), a recording segment past 4 GiB stops with it, the watch is atomic and the log line has three more counts. Host code: the runtime is rebuilt; nothing changes for players' saves, options or caches. Overlap: #1780 (snaildev99's, WIP) also changes the end-of-recording log line in `nvnCommandBufferEndRecording` (`host/nvn_native.c`); the two conflict there and nowhere else. Whichever is merged first goes first and the other rebases onto it: this one, if #1780 is first. ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. - [x] 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). - [ ] 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 - [ ] A switch added or changed: it ships at the default the measurements chose, with its row in `gpu/vk/switches.def`. - [ ] Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. - [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.
perf(nvn): a call of several recordings makes room for all of them at once (HOS_NVN_CALL_RESERVE=0 to disable)
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 21s
Website / Website on Cloudflare (pull_request_target) Has been skipped
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
15dbbfd830
nvnCommandBufferCallCommands and CopyCommands copy each called recording into the caller's segment. One at a time,
each called recording that did not fit grew the segment by doubling, a copy of everything it held at each step, so a
call of several large recordings could grow (and copy) the segment more than once. A call of several recordings now
checks all of the handles, makes room for all of their records once (cmd_reserve_rec), then copies each straight in
(inline_recordings; called_size is the records' size, inline_recording takes it). The bytes recorded and the command
memory counts are the same; a handle that is not live still dies before anything of it is copied, now before any of
the call is copied, which the game does not see.

HOS_NVN_CALL_RESERVE (new, kill switch, its row in gpu/vk/switches.def): on by default, as the branch shipped it;
=0 copies them one at a time, as before. Read once, published atomically (threads that come first together keep one answer).

On the branch this went with HOS_NVN_SEG_PEAK (3e8a2abd: a grown segment grows at once to the command buffer's
recent largest recording), whose micro-benchmark of the recording path (a large caller after small ones: 1000 ->
12 KB of grow copies, -21..-23 % recording time) is mostly that part; that part is not ported (a segment on main
never shrinks within a command buffer's life, so it only acts after the command buffer is initialized again, which
#1812's segment size hints tried; #1812 was closed unmerged by its author). The in-play A/B on the branch
(2cc8489c: Kokiri, i7-9700, RTX 4060) found no difference for HOS_NVN_SEG_PEAK as a whole. Not measured on its own.

Test: tests/test_nvn_call_reserve.py runs the real recording path cut from the source (slot table, cmd_reserve_rec,
cmd_alloc, BeginRecording, EndRecording up to its copy, flatten, inline_recordings, CallCommands, CopyCommands) through
3,000 recordings of twelve command buffers calling 1 to 6 earlier recordings at a time, with the switch on and off:
every recording's bytes and command memory counts the same, fewer segments asked for with it on.

#1812 (GummiNaomi, closed unmerged by its author: no change at 4 or 16 cores) prefetched the next handle in the
same CallCommands / CopyCommands loops; this makes the room for all of a call's recordings once instead.

The test sets the switch in each run's own process (unset, 0, off, No, 1, yes, 2, and 0 again) and sets it the
other way after its first read, which must not change the answer. The C compiler is --cc, $CC, LONGSHOT_MINGW's clang
on Windows, then clang, gcc or cc.

Assisted-by: Claude Code
Member

Possibly related, for context:

  • PR #1780 WIP: perf(host): a finished command recording is handed over instead of copied (HOS_NVN_REC_HANDOFF=0 to copy) — Touches NVN recording copy/segment handling in the same host file; distinct handoff optimization but nearby code may overlap.
Possibly related, for context: - PR #1780 WIP: perf(host): a finished command recording is handed over instead of copied (HOS_NVN_REC_HANDOFF=0 to copy) — Touches NVN recording copy/segment handling in the same host file; distinct handoff optimization but nearby code may overlap.
BeanBot left a comment

Recommendation: Request changes. The new path can use a different handle from the one it validated, can outlive a validated recording, and can overflow the batch capacity calculation. The reported fixture passes, but the player benefit and enabled default still need in-game evidence.

CallCommands and CopyCommands reserve space for a batch before copying records. This can avoid intermediate segment allocations and copies when a batch crosses several capacity thresholds. It also adds a handle-list and size pass to every multi-handle call, including calls whose segment already has room.

@fix will do (12)

  1. L1 host/nvn_native.c:1847: The batch copy re-reads the guest array after validation and reserve. (more on the line)
  2. L2 host/nvn_native.c:1844: A live-set hit does not pin the recording. (more on the line)
  3. L3 host/nvn_native.c:1843: The new batch total is unchecked, and cmd_reserve_rec adds used and OP_RESERVE and doubles cap unchecked. (more on the line)
  4. L4 (minor) host/nvn_native.c:1846: The extracted watch path carries forward a shared-state race. (more on the line)
  5. L5 (minor) host/nvn_native.c:1858: PN checks the reserved guest window. (more on the line)
  6. L6 (minor) gpu/vk/switches.def:121: The row promises that an empty value disables the switch. (more on the line)
  7. L7 (minor) tests/test_nvn_call_reserve.py:263: The growth assertion pools both entry points, and both sides share the copy helper. (more on the line)
  8. L8 (minor) tests/test_nvn_call_reserve.py:124: The fixture primes the switch directly before the first NVN call and only uses live handles. (more on the line)
  9. L9 (minor) tests/test_nvn_call_reserve.py:135: The fixture simulates reinitialization by zeroing the object, orphaning its slot and its potentially multi-megabyte segment. (more on the line)
  10. L10 (minor) tests/test_nvn_call_reserve.py:216: The compiler picker treats CC as a single filename. (more on the line)
  11. L11 (its part an edit can do) host/nvn_native.c:1841: Count multi-handle calls, growths, and bytes copied by growth. Reuse validated sizes and skip redundant reserve checks on the batch path.
  12. L12 (minor): The checkbox says current main, but local main is 40bfceb0 and the tested base is 75317e1f. The reported 47 checks are the changed-file selection and leave the whole-suite and lint requirements open. Keep the current-main box unticked until verified, and record the complete check and lint results for the updated head.

For the author (1) (a run, a measurement or a decision)

  • L11 (minor) host/nvn_native.c:1841: The malloc-backed fixture counts requests and cannot show whether batching helps in play. (more on the line)

Checks: Still running: CI / Conventional Commit title (pull_request), CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request), CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request), CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request), CI / Workflow lint (actionlint) (pull_request), CI / Website build and checks (pull_request), Guide screenshots / Guide images and local UI source review (pull_request), Third-party parts / As their notes say (pull_request), Third-party parts / The same as upstream (pull_request).

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

Does it help: Unproven. The author reports equivalent output and fewer segment requests in a 3,000-recording synthetic fixture, with no request totals published. The earlier combined HOS_NVN_SEG_PEAK branch showed no measurable gain in play. This head has no isolated in-game comparison with 75317e1f.

Other systems: The changed host path feeds every Vulkan vendor and both inline and threaded replay on Windows and Linux, including Steam Deck. Queue waits, deferred binding resolution and registration order are unchanged in the diff. Recording lifetime, diagnostic watches and host RAM are affected. The diff changes no save, audio, input, shader cache or renderer ABI code. No game run verifies rendering or frame pacing yet.

Switches: HOS_NVN_CALL_RESERVE is a new developer kill switch at gpu/vk/switches.def:121. Unset enables batching for calls with at least two handles. 0, false, off and no disable it, as does an empty value when the CRT preserves it. Enabled matches the branch's test configuration. Measurements still need to establish the shipping default.

Reviewed: 15dbbfd830 against 75317e1f31: Read AGENTS.md, CONTRIBUTING.md, docs/dev/standards.md, the Forgejo template, the commit and all three file diffs. Read the new test in full and the changed NVN functions with their allocation, handle publication and retirement, watch, guest range and submit code. Checked the switch table insertion, switch parser, source-cut helpers and test-runner discovery. No review checklist, PR run logs, comments or reviews were available. The rest of nvn_native.c, unrelated switch rows and unrelated recorded runs were skimmed.; nothing run (a code review).

Checked and fine:

  • The new cached integer uses atomic accesses throughout. Relaxed ordering is sufficient to publish a standalone boolean, and a losing compare-exchange returns the published result.
  • For a stable list of live recordings and representable sizes, payload order, BEGIN/END exclusion, empty-record handling and command counters match the previous loop.
  • The switch row is sorted and has the correct host prefix and kill-switch kind. The fixture isolates this switch in each child process.
  • The diff contains synthetic test data and no game-derived files, build artifacts, generated edits or third-party changes. The commit has an Assisted-by trailer. No renderer API version bump applies.
  • The fixture uses the standard library and its documented compile and child execution stay within its temporary-directory workflow.

Testing: Read-only review. The author reports 38 of 47 selected Windows checks passed, including the new fixture and switch table, with the same nine failures on the base. Forgejo checks were still running. Linux build and GCC fixture results, the full suite, lint and in-game results remain outstanding.

Overlaps and merge order: No overlapping open PR found in the supplied evidence or local history. The description identifies #1812 as closed and unmerged. No merge-order dependency found.


Automated code review by BeanBot (gpt-6.2-sol), on the pull request's opening. Nothing was run; a maintainer decides.

**Recommendation: Request changes.** The new path can use a different handle from the one it validated, can outlive a validated recording, and can overflow the batch capacity calculation. The reported fixture passes, but the player benefit and enabled default still need in-game evidence. CallCommands and CopyCommands reserve space for a batch before copying records. This can avoid intermediate segment allocations and copies when a batch crosses several capacity thresholds. It also adds a handle-list and size pass to every multi-handle call, including calls whose segment already has room. **`@fix` will do (12)** 1. **L1** `host/nvn_native.c:1847`: The batch copy re-reads the guest array after validation and reserve. (more on the line) 2. **L2** `host/nvn_native.c:1844`: A live-set hit does not pin the recording. (more on the line) 3. **L3** `host/nvn_native.c:1843`: The new batch total is unchecked, and cmd_reserve_rec adds used and OP_RESERVE and doubles cap unchecked. (more on the line) 4. **L4** (minor) `host/nvn_native.c:1846`: The extracted watch path carries forward a shared-state race. (more on the line) 5. **L5** (minor) `host/nvn_native.c:1858`: PN checks the reserved guest window. (more on the line) 6. **L6** (minor) `gpu/vk/switches.def:121`: The row promises that an empty value disables the switch. (more on the line) 7. **L7** (minor) `tests/test_nvn_call_reserve.py:263`: The growth assertion pools both entry points, and both sides share the copy helper. (more on the line) 8. **L8** (minor) `tests/test_nvn_call_reserve.py:124`: The fixture primes the switch directly before the first NVN call and only uses live handles. (more on the line) 9. **L9** (minor) `tests/test_nvn_call_reserve.py:135`: The fixture simulates reinitialization by zeroing the object, orphaning its slot and its potentially multi-megabyte segment. (more on the line) 10. **L10** (minor) `tests/test_nvn_call_reserve.py:216`: The compiler picker treats CC as a single filename. (more on the line) 11. **L11** (its part an edit can do) `host/nvn_native.c:1841`: Count multi-handle calls, growths, and bytes copied by growth. Reuse validated sizes and skip redundant reserve checks on the batch path. 12. **L12** (minor): The checkbox says current main, but local main is 40bfceb0 and the tested base is 75317e1f. The reported 47 checks are the changed-file selection and leave the whole-suite and lint requirements open. Keep the current-main box unticked until verified, and record the complete check and lint results for the updated head. **For the author (1)** (a run, a measurement or a decision) - **L11** (minor) `host/nvn_native.c:1841`: The malloc-backed fixture counts requests and cannot show whether batching helps in play. (more on the line) **Checks:** Still running: `CI / Conventional Commit title (pull_request)`, `CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request)`, `CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request)`, `CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request)`, `CI / Workflow lint (actionlint) (pull_request)`, `CI / Website build and checks (pull_request)`, `Guide screenshots / Guide images and local UI source review (pull_request)`, `Third-party parts / As their notes say (pull_request)`, `Third-party parts / The same as upstream (pull_request)`. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Unproven. The author reports equivalent output and fewer segment requests in a 3,000-recording synthetic fixture, with no request totals published. The earlier combined HOS_NVN_SEG_PEAK branch showed no measurable gain in play. This head has no isolated in-game comparison with 75317e1f. **Other systems:** The changed host path feeds every Vulkan vendor and both inline and threaded replay on Windows and Linux, including Steam Deck. Queue waits, deferred binding resolution and registration order are unchanged in the diff. Recording lifetime, diagnostic watches and host RAM are affected. The diff changes no save, audio, input, shader cache or renderer ABI code. No game run verifies rendering or frame pacing yet. **Switches:** HOS_NVN_CALL_RESERVE is a new developer kill switch at gpu/vk/switches.def:121. Unset enables batching for calls with at least two handles. 0, false, off and no disable it, as does an empty value when the CRT preserves it. Enabled matches the branch's test configuration. Measurements still need to establish the shipping default. **Reviewed:** 15dbbfd8300d against 75317e1f31ff: Read AGENTS.md, CONTRIBUTING.md, docs/dev/standards.md, the Forgejo template, the commit and all three file diffs. Read the new test in full and the changed NVN functions with their allocation, handle publication and retirement, watch, guest range and submit code. Checked the switch table insertion, switch parser, source-cut helpers and test-runner discovery. No review checklist, PR run logs, comments or reviews were available. The rest of nvn_native.c, unrelated switch rows and unrelated recorded runs were skimmed.; nothing run (a code review). **Checked and fine:** - The new cached integer uses atomic accesses throughout. Relaxed ordering is sufficient to publish a standalone boolean, and a losing compare-exchange returns the published result. - For a stable list of live recordings and representable sizes, payload order, BEGIN/END exclusion, empty-record handling and command counters match the previous loop. - The switch row is sorted and has the correct host prefix and kill-switch kind. The fixture isolates this switch in each child process. - The diff contains synthetic test data and no game-derived files, build artifacts, generated edits or third-party changes. The commit has an Assisted-by trailer. No renderer API version bump applies. - The fixture uses the standard library and its documented compile and child execution stay within its temporary-directory workflow. **Testing:** Read-only review. The author reports 38 of 47 selected Windows checks passed, including the new fixture and switch table, with the same nine failures on the base. Forgejo checks were still running. Linux build and GCC fixture results, the full suite, lint and in-game results remain outstanding. **Overlaps and merge order:** No overlapping open PR found in the supplied evidence or local history. The description identifies #1812 as closed and unmerged. No merge-order dependency found. </details> --- <sub>Automated code review by BeanBot (gpt-6.2-sol), on the pull request's opening. Nothing was run; a maintainer decides.</sub>
@ -118,6 +118,7 @@ SW(HOS_NO_PRIORITIES, kill, bool, "Windows: boosted threads get above-normal or
SW(HOS_NO_RENDERER_WAIT, kill, bool, "the game's first GPU work waits for the renderer", "Non-zero skips the wait for the renderer before the game's first GPU work, as before lighting-fix.")
SW(HOS_NO_SDL, kill, bool, "SDL controllers on", "SDL's controller thread is never started: no SDL pads, only XInput.")
SW(HOS_NO_THP, attempt, bool, "off: THP as the system sets it outside the guest window", "=1 disables transparent huge pages for the whole process (PR_SET_THP_DISABLE).")
SW(HOS_NVN_CALL_RESERVE, kill, bool, "on: a CallCommands or CopyCommands of several recordings checks them all and makes room for all of them before copying any", "=0 (or false, off, no, empty; any other value is on) copies them one at a time, the segment growing for each that does not fit, as before. Read once, at the first such call.")
Member

L6 (minor): The row promises that an empty value disables the switch. On Windows, the file loader passes NAME= to _putenv, which removes the variable, so an empty HOS_NVN_CALL_RESERVE entry in longshot_env.txt leaves batching enabled. Document that case and give =0 as the portable spelling. Also describe the first value as cached, since simultaneous first callers can each read the environment before one publishes.

**L6** (minor): The row promises that an empty value disables the switch. On Windows, the file loader passes NAME= to _putenv, which removes the variable, so an empty HOS_NVN_CALL_RESERVE entry in longshot_env.txt leaves batching enabled. Document that case and give =0 as the portable spelling. Also describe the first value as cached, since simultaneous first callers can each read the environment before one publishes.
@ -1823,2 +1855,4 @@
}
}
NV(nvnCommandBufferCallCommands) {
const uint64_t *h = (const uint64_t *)PN(2, 8ull * (uint32_t)I(1));
Member

L5 (minor): PN checks the reserved guest window. A positive count with a null array still reaches h[0], and a list crossing into an unmapped region can pass PN and fault during the scan. This is inherited at these entry points. Share argument validation between both wrappers, handle zero count before pointer translation, and reject invalid counts, missing arrays and spans outside mapped guest memory through the NVN diagnostic.

**L5** (minor): PN checks the reserved guest window. A positive count with a null array still reaches h[0], and a list crossing into an unmapped region can pass PN and fault during the scan. This is inherited at these entry points. Share argument validation between both wrappers, handle zero count before pointer translation, and reject invalid counts, missing arrays and spans outside mapped guest memory through the NVN diagnostic.
@ -1823,0 +1838,4 @@
return on;
}
static void inline_recordings(Ctx *c, nvn_cmd *o, const uint64_t *h, int n, const char *how) {
if (n > 1 && call_reserve_on()) {
Member

L11 (minor): The malloc-backed fixture counts requests and cannot show whether batching helps in play. Run the base, head with the switch off and head with it unset on the same builds and settings, with warmed interleaved repeats in Kokiri Forest and a heavy area such as Castle Town Market. Report average FPS, 1% lows, median and p99 frame times, and peak host memory. Complete the own-PC game run and Tier 1 Windows, Linux and Deck checks before merge.

**L11** (minor): The malloc-backed fixture counts requests and cannot show whether batching helps in play. Run the base, head with the switch off and head with it unset on the same builds and settings, with warmed interleaved repeats in Kokiri Forest and a heavy area such as Castle Town Market. Report average FPS, 1% lows, median and p99 frame times, and peak host memory. Complete the own-PC game run and Tier 1 Windows, Linux and Deck checks before merge.
@ -1823,0 +1840,4 @@
static void inline_recordings(Ctx *c, nvn_cmd *o, const uint64_t *h, int n, const char *how) {
if (n > 1 && call_reserve_on()) {
size_t all = 0;
for (int i = 0; i < n; i++) check_handle(h[i]), all += called_size(h[i]);
Member

L3: The new batch total is unchecked, and cmd_reserve_rec adds used and OP_RESERVE and doubles cap unchecked. A list can repeat the same live large recording, so total bytes can exceed what a host segment can represent even when the source recording and array each fit. The sum can wrap or capacity can double through zero and loop forever before allocation. Check accumulation, reserve padding and capacity growth against a representable allocation limit, then fail through the normal fatal path. Cover the limit in the fixture with synthetic sizes.

**L3**: The new batch total is unchecked, and cmd_reserve_rec adds used and OP_RESERVE and doubles cap unchecked. A list can repeat the same live large recording, so total bytes can exceed what a host segment can represent even when the source recording and array each fit. The sum can wrap or capacity can double through zero and loop forever before allocation. Check accumulation, reserve padding and capacity growth against a representable allocation limit, then fail through the normal fatal path. Cover the limit in the fixture with synthetic sizes.
@ -1823,0 +1841,4 @@
if (n > 1 && call_reserve_on()) {
size_t all = 0;
for (int i = 0; i < n; i++) check_handle(h[i]), all += called_size(h[i]);
if (all) cmd_reserve_rec(cmd_host(o), all);
Member

L2: A live-set hit does not pin the recording. AddControlMemory or the overwrite sweep can retire an early handle while this call validates the rest or waits in reserve. free_dead_copies waits for replay submits, which does not protect this CPU copy. The second pass can then read a freed or reused prefix. The old path already had a shorter check-to-copy window. Hold a lifetime reference from validation through memcpy, with retirement deferring reclamation until that reference is released. Keep allocation retries outside copy_lock.

**L2**: A live-set hit does not pin the recording. AddControlMemory or the overwrite sweep can retire an early handle while this call validates the rest or waits in reserve. free_dead_copies waits for replay submits, which does not protect this CPU copy. The second pass can then read a freed or reused prefix. The old path already had a shorter check-to-copy window. Hold a lifetime reference from validation through memcpy, with retirement deferring reclamation until that reference is released. Keep allocation retries outside copy_lock.
@ -1823,0 +1843,4 @@
for (int i = 0; i < n; i++) check_handle(h[i]), all += called_size(h[i]);
if (all) cmd_reserve_rec(cmd_host(o), all);
for (int i = 0; i < n; i++) {
if (nwatch_handles) watch_handle_called(c, h[i], how);
Member

L4 (minor): The extracted watch path carries forward a shared-state race. EndRecording increments nwatch_handles while CallCommands and CopyCommands read it and scan watch_handles. Two writers that match watch_draw_cmd can also race through the 16-entry limit. With HOS_NVN_WATCH_DRAW enabled, synchronize the pending buffer and table update, publish initialized entries before the count, and read a stable snapshot before logging.

**L4** (minor): The extracted watch path carries forward a shared-state race. EndRecording increments nwatch_handles while CallCommands and CopyCommands read it and scan watch_handles. Two writers that match watch_draw_cmd can also race through the 16-entry limit. With HOS_NVN_WATCH_DRAW enabled, synchronize the pending buffer and table update, publish initialized entries before the count, and read a stable snapshot before logging.
@ -1823,0 +1844,4 @@
if (all) cmd_reserve_rec(cmd_host(o), all);
for (int i = 0; i < n; i++) {
if (nwatch_handles) watch_handle_called(c, h[i], how);
inline_recording(o, h[i], called_size(h[i]));
Member

L1: The batch copy re-reads the guest array after validation and reserve. If a slot changes while the host allocates, called_size can follow the replacement without checking it. The fallback also reloads h[i] after check_handle, where main passed one value into inline_recording. Capture each handle once and use the captured handle and size for the copy. A bounded snapshot with the original one-at-a-time path for larger lists would keep temporary storage predictable.

**L1**: The batch copy re-reads the guest array after validation and reserve. If a slot changes while the host allocates, called_size can follow the replacement without checking it. The fallback also reloads h[i] after check_handle, where main passed one value into inline_recording. Capture each handle once and use the captured handle and size for the copy. A bounded snapshot with the original one-at-a-time path for larger lists would keep temporary storage predictable.
@ -0,0 +121,4 @@
int main(int argc, char **argv) {
if (argc != 3) return 1;
test_reserve = atoi(argv[1]);
read_once(call_reserve_on, "HOS_NVN_CALL_RESERVE", test_reserve);
Member

L8 (minor): The fixture primes the switch directly before the first NVN call and only uses live handles. It would miss a single-handle call caching the answer early or the batch validation being removed. Drive first use through both entry points in fresh children, exercise invalid-handle rejection with a bad later handle, and cover simultaneous first callers. Add the advertised false and empty cases where the runtime preserves them.

**L8** (minor): The fixture primes the switch directly before the first NVN call and only uses live handles. It would miss a single-handle call caching the answer early or the batch validation being removed. Drive first use through both entry points in fresh children, exercise invalid-handle rejection with a bad later handle, and cover simultaneous first callers. Add the advertised false and empty cases where the runtime preserves them.
@ -0,0 +132,4 @@
for (int k = 0; k < recordings; k++) {
const int which = (int)(rnd() % NCMD);
nvn_cmd *o = &cmds[which];
if (rnd() % 100 == 0) /* (initialized anew: a new slot, a new segment from 64 KiB; the old one is left) */
Member

L9 (minor): The fixture simulates reinitialization by zeroing the object, orphaning its slot and its potentially multi-megabyte segment. Real Initialize releases both. This makes the growth counts depend on leaked segments and increases memory use on small CI workers. Exercise the real release and initialization path and free surviving fixture allocations at teardown.

**L9** (minor): The fixture simulates reinitialization by zeroing the object, orphaning its slot and its potentially multi-megabyte segment. Real Initialize releases both. This makes the growth counts depend on leaked segments and increases memory use on small CI workers. Exercise the real release and initialization path and free surviving fixture allocations at teardown.
@ -0,0 +213,4 @@
def compiler(given):
"""--cc, else $CC, else the configured llvm-mingw's clang (LONGSHOT_MINGW, Windows: run_all.py sets it to the
clone's folder), else clang, gcc or cc on PATH"""
for c in (given, os.environ.get("CC")):
Member

L10 (minor): The compiler picker treats CC as a single filename. CC='ccache gcc' fails when subprocess tries to execute that literal name. A direct Windows invocation also misses the clone's llvm-mingw unless the runner has populated LONGSHOT_MINGW. Support compiler command arguments while preserving explicit executable paths with spaces, and try the clone-local toolchain as the runner does.

**L10** (minor): The compiler picker treats CC as a single filename. CC='ccache gcc' fails when subprocess tries to execute that literal name. A direct Windows invocation also misses the clone's llvm-mingw unless the runner has populated LONGSHOT_MINGW. Support compiler command arguments while preserving explicit executable paths with spaces, and try the clone-local toolchain as the runner does.
@ -0,0 +260,4 @@
if len(a) != 3000 or multi < 1000:
print("FAIL: %d recordings, %d calls of several" % (len(a), multi))
sys.exit(1)
if gets_on >= gets_off:
Member

L7 (minor): The growth assertion pools both entry points, and both sides share the copy helper. CopyCommands can fall back to the old growth pattern while CallCommands satisfies the aggregate. Dropping the same record on both sides can also leave their hashes equal. Add a small deterministic case per API that forces two old growths and one batched growth, and assert independently constructed bytes and memory counts.

**L7** (minor): The growth assertion pools both entry points, and both sides share the copy helper. CopyCommands can fall back to the old growth pattern while CallCommands satisfies the aggregate. Dropping the same record on both sides can also leave their hashes equal. Add a small deterministic case per API that forces two old growths and one batched growth, and assert independently constructed bytes and memory counts.
siantm force-pushed perf/nvn-call-reserve from 15dbbfd830
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 21s
Website / Website on Cloudflare (pull_request_target) Has been skipped
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
to eac243608f
Some checks failed
Website / Website on Cloudflare (pull_request_target) Has been skipped
beanstalk/approval waiting for a BigBean's 👍 on the request
PR description / Description follows the template (pull_request_target) Successful in 4s
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
Website / Website on Cloudflare (pull_request) Has been cancelled
2026-11-21 08:21:40 +00:00
Compare
siantm changed title from WIP: perf(nvn): a call of several recordings makes room for all of them at once (HOS_NVN_CALL_RESERVE=0 to disable) to WIP: perf(nvn): a call of several recordings makes room for all of them at once (HOS_NVN_CALL_RESERVE=1 to try it) 2026-11-21 08:21:57 +00:00
Author
Contributor

Thank you for the review (#issuecomment-64237). Pushed eac24360, rebased on main @ 7c23d2be (main has since added only pipeline-state lists, #2041) (the branch's own commit unchanged by the rebase, git range-diff); test commit 2c924d1a (its new checks fail on the branch's earlier code: queue job fb-2023-5; its cases one by one on that code in fb-2023-3), fix eac24360. All checks named below ran in queue jobs on this PC (fb-2023-1, fb-2023-3, fb-2023-5); nothing has run in the game.

Default: there is no measurement in play, so HOS_NVN_CALL_RESERVE is now off by default (kind attempt): unset is main's one-at-a-time copy, =1 turns the batch on. The in-game A/B that could turn it on is in Still to test. The title says so.

  • L1 (#issuecomment-64226), the array read again after the check: fixed in eac24360: a call of 2 to 64 handles copies the guest's array once into a local snapshot with each handle's size, checks those and copies those; a larger call goes one at a time, and that loop reads each handle once and passes the same value to the watch, the check and the copy. The fixture's pin case changes the game's array to another live recording while the call makes its room: the call copies the recordings it checked (bytes compared with the records as written), for CallCommands and CopyCommands.
  • L2 (#issuecomment-64227), a checked recording freed before its copy: fixed in eac24360: the call counts itself in calls_copying from before its first check to after its last copy, and free_dead_copies frees nothing while that count is not zero (seq_cst fences on both sides, so either the call's check sees the release or the free sees the call); the next AddControlMemory or sweep frees what it left. The allocation stays outside copy_lock, which the call does not take. The pin case releases the called recordings (their control memory added again) and runs another AddControlMemory with the replay past them while the call makes its room: nothing is freed during the call, the bytes are the recordings', and the next AddControlMemory frees both. On the branch's code that case fails. The one-at-a-time path (the default) is main's, with main's shorter window; I left it as it is.
  • L3 (#issuecomment-64228), the sums and the doubling: fixed in eac24360: CMD_SEG_MAX (4 GiB, a power of two as the capacities are): the call's sum is checked before each add, and cmd_reserve_rec stops past it before its sum or its doubling can wrap, both through die (the NVN diagnostic). The fixture's huge case calls a live handle claiming 2^63 bytes alone, twice and after a small recording, on and off: each stops with that message (on the branch's code, two of them loop forever doubling through zero and the others fail allocating).
  • L4 (#issuecomment-64229), the watch's shared state: fixed in eac24360: the watched draw's command buffer is taken by one EndRecording with a compare-exchange, its slot claimed with an atomic add (past 16, none), the handle stored with a release store; the calls read each of the 16 slots once with an acquire load and skip empty ones. No test of its own: it is a race in a diagnostic, checked by reading; the fixture now runs the real watch code on every call.
  • L5 (#issuecomment-64230), the count and the array: fixed in eac24360 for both wrappers in one place (call_handles): a count of 0 reads nothing, a negative count or a count with no array stops with the diagnostic naming the call; the array must lie in the guest window as before (gw). The fixture's args case checks all three for both calls (a count with no array read address 0 before). I did not add a mapped-memory check of the array: the only one, hos_mem_mapped, takes hos_mem.c's lock, which would put a lock on every call on the default path; a guest array outside mapped memory faults as it does for every other guest pointer the NVN layer reads.
  • L6 (#issuecomment-64231), the row: fixed in eac24360: off unless set, =0 off everywhere, an empty value in longshot_env.txt on Windows removes the variable (off, as unset), and the first value described as cached, with simultaneous first callers each possibly reading the variable and all keeping the first answer stored.
  • L7 (#issuecomment-64232), the pooled growth assertion: fixed in 2c924d1a: the first case runs for CallCommands and for CopyCommands on its own: three 48 KiB recordings into a 64 KiB segment grow it twice one at a time and once with the room first, and the caller's bytes and command memory counts are compared with the records as the fixture wrote them and their sizes, not with another run.
  • L8 (#issuecomment-64233), the switch primed and only live handles: fixed in 2c924d1a: no case primes the switch; in first a call of one recording comes first and the variable is set only after it, so a single-handle call that read it would keep the other answer; the 3,000-recording run's first read is its first call of several. The real check_handle and live-handle set are cut from the source: bad calls two live handles and then one whose prefix is right but that EndRecording never made: on, the call stops with nothing copied; off, after the first two, as on main. race (a separate build of call_reserve_on with its reader replaced) has eight threads come first together, the reader answering each differently: all keep one answer. False and empty are among the cases, each with the child's environment set explicitly (empty reads as off whether the runtime keeps it or not).
  • L9 (#issuecomment-64234), the zeroed objects: fixed in 2c924d1a: the fixture runs the real nvnCommandBufferInitialize (its segment and slot given back) and Finalize, and frees every command buffer, kept recording and fixture block at the end.
  • L10 (#issuecomment-64235), the compiler: fixed in 2c924d1a: --cc and CC go through tests/compiler_command.py's parse_compiler (a path with spaces kept, a command with arguments split), then LONGSHOT_MINGW's clang, then the clone's llvm-mingw as run_all.py finds it, then clang, gcc or cc. It ran with no --cc and no CC in fb-2023-3, fb-2023-5.
  • L11 (in 64237, and #issuecomment-64236), counts and the measurement: the edit part is fixed in eac24360: the recordings' log line counts the segments' growths, the bytes those growths copied and the calls given their room at once (the first case checks the counts against its own), and the batch copies with the sizes it checked into the room made once, without a reserve per handle. The A/B is pending, for the owner: main, this PR unset and with =1, warmed and interleaved, in Kokiri Forest and Castle Town Market, with average fps, 1% lows, median and p99 frame times, peak host memory and the log line's counts, and the Tier 1 runs; Still to test lists them.
  • L12 (in 64237), the checklist and the checks: the branch is now on main @ 7c23d2be, which Tested names; main has since added only contributed pipeline-state lists (#2041), so the current-main box stays unticked. Tested lists what ran here: the PR's own checks and every check --changed 7c23d2be picks, with the failures that fail on main too. The whole suite and lint did not run on this PC (pre-commit and ruff are not installed here); they are in Still to test, and the mise run test box stays unticked.
Thank you for the review (#issuecomment-64237). Pushed eac24360, rebased on main @ 7c23d2be (main has since added only pipeline-state lists, #2041) (the branch's own commit unchanged by the rebase, `git range-diff`); test commit 2c924d1a (its new checks fail on the branch's earlier code: queue job fb-2023-5; its cases one by one on that code in fb-2023-3), fix eac24360. All checks named below ran in queue jobs on this PC (fb-2023-1, fb-2023-3, fb-2023-5); nothing has run in the game. **Default:** there is no measurement in play, so `HOS_NVN_CALL_RESERVE` is now off by default (kind attempt): unset is main's one-at-a-time copy, `=1` turns the batch on. The in-game A/B that could turn it on is in Still to test. The title says so. - **L1** ([#issuecomment-64226](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2023#issuecomment-64226)), the array read again after the check: fixed in eac24360: a call of 2 to 64 handles copies the guest's array once into a local snapshot with each handle's size, checks those and copies those; a larger call goes one at a time, and that loop reads each handle once and passes the same value to the watch, the check and the copy. The fixture's `pin` case changes the game's array to another live recording while the call makes its room: the call copies the recordings it checked (bytes compared with the records as written), for CallCommands and CopyCommands. - **L2** ([#issuecomment-64227](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2023#issuecomment-64227)), a checked recording freed before its copy: fixed in eac24360: the call counts itself in `calls_copying` from before its first check to after its last copy, and `free_dead_copies` frees nothing while that count is not zero (seq_cst fences on both sides, so either the call's check sees the release or the free sees the call); the next AddControlMemory or sweep frees what it left. The allocation stays outside `copy_lock`, which the call does not take. The `pin` case releases the called recordings (their control memory added again) and runs another AddControlMemory with the replay past them while the call makes its room: nothing is freed during the call, the bytes are the recordings', and the next AddControlMemory frees both. On the branch's code that case fails. The one-at-a-time path (the default) is main's, with main's shorter window; I left it as it is. - **L3** ([#issuecomment-64228](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2023#issuecomment-64228)), the sums and the doubling: fixed in eac24360: `CMD_SEG_MAX` (4 GiB, a power of two as the capacities are): the call's sum is checked before each add, and `cmd_reserve_rec` stops past it before its sum or its doubling can wrap, both through `die` (the NVN diagnostic). The fixture's `huge` case calls a live handle claiming 2^63 bytes alone, twice and after a small recording, on and off: each stops with that message (on the branch's code, two of them loop forever doubling through zero and the others fail allocating). - **L4** ([#issuecomment-64229](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2023#issuecomment-64229)), the watch's shared state: fixed in eac24360: the watched draw's command buffer is taken by one EndRecording with a compare-exchange, its slot claimed with an atomic add (past 16, none), the handle stored with a release store; the calls read each of the 16 slots once with an acquire load and skip empty ones. No test of its own: it is a race in a diagnostic, checked by reading; the fixture now runs the real watch code on every call. - **L5** ([#issuecomment-64230](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2023#issuecomment-64230)), the count and the array: fixed in eac24360 for both wrappers in one place (`call_handles`): a count of 0 reads nothing, a negative count or a count with no array stops with the diagnostic naming the call; the array must lie in the guest window as before (`gw`). The fixture's `args` case checks all three for both calls (a count with no array read address 0 before). I did not add a mapped-memory check of the array: the only one, `hos_mem_mapped`, takes `hos_mem.c`'s lock, which would put a lock on every call on the default path; a guest array outside mapped memory faults as it does for every other guest pointer the NVN layer reads. - **L6** ([#issuecomment-64231](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2023#issuecomment-64231)), the row: fixed in eac24360: off unless set, `=0` off everywhere, an empty value in `longshot_env.txt` on Windows removes the variable (off, as unset), and the first value described as cached, with simultaneous first callers each possibly reading the variable and all keeping the first answer stored. - **L7** ([#issuecomment-64232](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2023#issuecomment-64232)), the pooled growth assertion: fixed in 2c924d1a: the `first` case runs for CallCommands and for CopyCommands on its own: three 48 KiB recordings into a 64 KiB segment grow it twice one at a time and once with the room first, and the caller's bytes and command memory counts are compared with the records as the fixture wrote them and their sizes, not with another run. - **L8** ([#issuecomment-64233](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2023#issuecomment-64233)), the switch primed and only live handles: fixed in 2c924d1a: no case primes the switch; in `first` a call of one recording comes first and the variable is set only after it, so a single-handle call that read it would keep the other answer; the 3,000-recording run's first read is its first call of several. The real `check_handle` and live-handle set are cut from the source: `bad` calls two live handles and then one whose prefix is right but that EndRecording never made: on, the call stops with nothing copied; off, after the first two, as on main. `race` (a separate build of `call_reserve_on` with its reader replaced) has eight threads come first together, the reader answering each differently: all keep one answer. False and empty are among the cases, each with the child's environment set explicitly (empty reads as off whether the runtime keeps it or not). - **L9** ([#issuecomment-64234](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2023#issuecomment-64234)), the zeroed objects: fixed in 2c924d1a: the fixture runs the real `nvnCommandBufferInitialize` (its segment and slot given back) and `Finalize`, and frees every command buffer, kept recording and fixture block at the end. - **L10** ([#issuecomment-64235](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2023#issuecomment-64235)), the compiler: fixed in 2c924d1a: `--cc` and `CC` go through `tests/compiler_command.py`'s `parse_compiler` (a path with spaces kept, a command with arguments split), then `LONGSHOT_MINGW`'s clang, then the clone's `llvm-mingw` as `run_all.py` finds it, then clang, gcc or cc. It ran with no `--cc` and no `CC` in fb-2023-3, fb-2023-5. - **L11** (in 64237, and [#issuecomment-64236](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2023#issuecomment-64236)), counts and the measurement: the edit part is fixed in eac24360: the recordings' log line counts the segments' growths, the bytes those growths copied and the calls given their room at once (the `first` case checks the counts against its own), and the batch copies with the sizes it checked into the room made once, without a reserve per handle. The A/B is pending, for the owner: main, this PR unset and with `=1`, warmed and interleaved, in Kokiri Forest and Castle Town Market, with average fps, 1% lows, median and p99 frame times, peak host memory and the log line's counts, and the Tier 1 runs; Still to test lists them. - **L12** (in 64237), the checklist and the checks: the branch is now on main @ 7c23d2be, which Tested names; main has since added only contributed pipeline-state lists (#2041), so the current-main box stays unticked. Tested lists what ran here: the PR's own checks and every check `--changed 7c23d2be` picks, with the failures that fail on main too. The whole suite and lint did not run on this PC (pre-commit and ruff are not installed here); they are in Still to test, and the `mise run test` box stays unticked.
Author
Contributor

@Beanstalk This adds HOS_NVN_CALL_RESERVE, off by default: with HOS_NVN_CALL_RESERVE=1, NVN CallCommands and CopyCommands of several recordings reserve their room once (host/nvn_native.c); unset, main's way. It has not run in the game on these PCs yet. Please play Hyrule Field for three minutes, the PR against main on the same PC, on the PR's side with HOS_NVN_CALL_RESERVE=1 and with it unset, with a picture compared with main's, on Linux with NVIDIA, Linux with AMD (RADV), Windows with Intel and the Steam Deck. The same picture, no crash, no FATAL line and no "not a live recording" line either way; set, fewer segment growths and fewer MB copied in the recordings' log line than unset, and frame time p99 equal to unset or better. Please report that line's counts.

@Beanstalk This adds HOS_NVN_CALL_RESERVE, off by default: with HOS_NVN_CALL_RESERVE=1, NVN CallCommands and CopyCommands of several recordings reserve their room once (host/nvn_native.c); unset, main's way. It has not run in the game on these PCs yet. Please play Hyrule Field for three minutes, the PR against main on the same PC, on the PR's side with HOS_NVN_CALL_RESERVE=1 and with it unset, with a picture compared with main's, on Linux with NVIDIA, Linux with AMD (RADV), Windows with Intel and the Steam Deck. The same picture, no crash, no FATAL line and no "not a live recording" line either way; set, fewer segment growths and fewer MB copied in the recordings' log line than unset, and frame time p99 equal to unset or better. Please report that line's counts.
Member

@siantm only members of BigBeans can start the farm.

One of them can approve this request by reacting 👍 to it or to this comment. This request was for eac2436, and the PR has changed since (39fe40d), so a 👍 no longer approves it. Comment @Beanstalk again to ask for the new commit.

@siantm only members of `BigBeans` can start the farm. ~~One of them can approve this request by reacting 👍 to it or to this comment.~~ This request was for `eac2436`, and the PR has changed since (`39fe40d`), so a 👍 no longer approves it. Comment `@Beanstalk` again to ask for the new commit.
Author
Contributor

Risks now says plainly that, with HOS_NVN_CALL_RESERVE=1, released recording copies held while calls of several recordings copy are not bounded at eac24360 (no cap, no wait, no point each frame where the count is zero), with the lines and the bound to add before it could be turned on; Still to test has the Market run that measures the held memory and the wait. No code change, no push.

Risks now says plainly that, with HOS_NVN_CALL_RESERVE=1, released recording copies held while calls of several recordings copy are not bounded at eac24360 (no cap, no wait, no point each frame where the count is zero), with the lines and the bound to add before it could be turned on; Still to test has the Market run that measures the held memory and the wait. No code change, no push.
dyst left a comment

Verdict: Request changes. The revision closes BeanBot's use-after-free (L2), but it closes it with a global gate on free_dead_copies that can hold released recording copies without bound while the switch is on, as Risks says itself. A simpler order needs no new lifetime mechanism: check and size the handles, make the room once, then check each handle again at its copy, as main does. That should change before the farm or the A/B measure this code.

For a player, with HOS_NVN_CALL_RESERVE=1 a CallCommands or CopyCommands of 2 to 64 recordings grows the caller's segment once instead of once per recording that doesn't fit. Fewer reallocations and copies could mean a little less CPU on the recording threads, but nothing is measured yet, and the earlier HOS_NVN_SEG_PEAK (of which this was half) and #1812 measured no change in play. Unset, it is main's path plus hardening that regresses nothing: call_handles stops on a null array or a negative count instead of reading address 0, CMD_SEG_MAX stops a wrapped size, the watch is atomic, and the log line has three more counts.

Reviewed: eac24360 against 7c23d2be (the merge base with main): host/nvn_native.c (the whole diff, and the code it relies on: check_handle, the live-handle set, release_copies, sweep_overwritten_copies, free_dead_copies, dead_copy_add, cmd_reserve_rec, gw/PN, the watch's setter in watch_draw), gpu/vk/switches.def, tests/test_nvn_call_reserve.py in full and tests/test_recording_log_handoff.py. BeanBot's points were checked against the code, not only the reply. Nothing run (a code review).
Fixed in this review: nothing.
Checked and fine:

  • L1: the batch takes one snapshot of the guest array (hs), then checks, sizes and copies those values. The one-at-a-time loop reads h[i] once and passes it to the watch, the check and the copy.
  • L2 as a use-after-free: release clears the magic and removes the handle, and free_dead_copies frees only under the exclusive lock. With the two seq_cst fences, either the call's check sees the removal and stops, or the free sees calls_copying and skips. The pin case fails if the calls_copying test is taken out (the fixture's replay is always past the release).
  • L3: the call's sum is checked before each add. In cmd_reserve_rec, used stays at or below CMD_SEG_MAX - OP_RESERVE (cap is a power of two at most CMD_SEG_MAX, and the writes stay within what was reserved), so the new bound can't underflow and the doubling can't wrap.
  • L5 and L6: one place for the count and the array, and the row now says off unless set, with the Windows empty-value case.
  • L7 to L10: per-API first cases with the expected bytes built separately, a first read through a one-handle call, bad with a prefix that EndRecording never made, the real Initialize and Finalize, and parse_compiler (it is on main).
  • L11: the growth counts are on the log line, and nothing parses that line.
  • The default path's only new cost is an mfence in free_dead_copies when something is due, under a lock it already holds. That is negligible.
  • CALL_AT_ONCE puts 1 KiB on the stack, and a larger call falls back to main's loop. The test writes only to its own temporary folder and downloads nothing.

Blocking (to change before merge)

  1. host/nvn_native.c:1586 (free_dead_copies) and :1889/:1904 (inline_recordings): every free is skipped while any thread is inside a batched call. Nothing makes that count reach zero at a free: several job threads calling recordings back to back, as in the Market, can keep it above zero at each AddControlMemory and sweep. The held copies then grow with what the game releases, and on main they go once the replay passes them. Risks names this, and the "Still to test" Market run would only measure it. The epoch bound in Risks is one way to fix it. A simpler one removes the mechanism altogether:

    • phase 1: snapshot, check_handle, called_size and the sum, then cmd_reserve_rec(r, all) once;
    • phase 2, for each snapshot handle: check_handle again, then inline_recording (its cmd_reserve_rec returns at once when the room is there) and the copy.

    The check-to-copy window is then main's, without even the allocation in it. A handle the game released meanwhile stops the call as main would, and a bad handle still stops the call before anything is copied. calls_copying, the fences and the change to free_dead_copies all go. The second check is one lock-free probe per handle, small next to the memcpy. The pin case would then check that a handle released during the room-making stops the call (or still copies its live replacement), and that the frees aren't held.

Suggestions (the author may take or leave)

  • host/nvn_native.c:1586: if calls_copying stays, its load wants __ATOMIC_ACQUIRE (or an acquire fence after it). The seq_cst fence comes before the load, so in C11 terms a call's memcpy reads are not ordered before the pool_put that follows a read of 0. x86 hides this, but the compiler is free to move the later code.
  • host/nvn_native.c:2323: watch_draw_cmd = P(0) is still a plain store, while the readers now use atomics. An __atomic_store_n(..., __ATOMIC_RELAXED) would make the L4 fix whole. It is a diagnostic only.

Questions

  • With two A/B steps of the old HOS_NVN_SEG_PEAK showing no difference, what segment-growth rate in a real Market call would make this worth a switch? The log line's new counts, from one own-PC run with it on, would answer that before a farm run.

Testing: the author ran the PR's own checks and the --changed selection on Windows (i7-9700, RTX 4060). The 9 failures also fail on main. It has not run in the game anywhere: AGENTS.md wants the author's own in-game run first, and the Test Farm is for hardware the author doesn't have. The @Beanstalk request (Hyrule Field, Linux NVIDIA and AMD, Windows Intel, Steam Deck) should wait for the change above, since it would measure code that changes. When it runs, it should also report the log line's live copies (MB) and peak host memory, on and off: that is the regression a batched call could cause. It should include Castle Town Market, where these calls are heaviest, and run more than one interleaved pass a side, so "p99 equal or better" has a spread to be judged against. CI is still pending.
Overlaps and merge order:

  • #2025 and #2022 (both yours) rework release_copies, free_dead_copies and the sweep. Blocking 1's way leaves free_dead_copies alone and avoids that clash.
  • #2050 (yours) splits cmd_reserve_rec into an inline fast path and a slow path, and the CMD_SEG_MAX check belongs in its slow path. Whichever merges second rebases onto the other.
  • #1780 adds counts to the same log line, a textual conflict only.
  • The others listed touch other parts of the file, and the switches.def row is the usual textual conflict.
**Verdict: Request changes.** The revision closes BeanBot's use-after-free (L2), but it closes it with a global gate on `free_dead_copies` that can hold released recording copies without bound while the switch is on, as Risks says itself. A simpler order needs no new lifetime mechanism: check and size the handles, make the room once, then check each handle again at its copy, as main does. That should change before the farm or the A/B measure this code. For a player, with `HOS_NVN_CALL_RESERVE=1` a CallCommands or CopyCommands of 2 to 64 recordings grows the caller's segment once instead of once per recording that doesn't fit. Fewer reallocations and copies could mean a little less CPU on the recording threads, but nothing is measured yet, and the earlier `HOS_NVN_SEG_PEAK` (of which this was half) and #1812 measured no change in play. Unset, it is main's path plus hardening that regresses nothing: `call_handles` stops on a null array or a negative count instead of reading address 0, `CMD_SEG_MAX` stops a wrapped size, the watch is atomic, and the log line has three more counts. **Reviewed:** eac24360 against 7c23d2be (the merge base with main): `host/nvn_native.c` (the whole diff, and the code it relies on: `check_handle`, the live-handle set, `release_copies`, `sweep_overwritten_copies`, `free_dead_copies`, `dead_copy_add`, `cmd_reserve_rec`, `gw`/`PN`, the watch's setter in `watch_draw`), `gpu/vk/switches.def`, `tests/test_nvn_call_reserve.py` in full and `tests/test_recording_log_handoff.py`. BeanBot's points were checked against the code, not only the reply. Nothing run (a code review). **Fixed in this review:** nothing. **Checked and fine:** - L1: the batch takes one snapshot of the guest array (`hs`), then checks, sizes and copies those values. The one-at-a-time loop reads `h[i]` once and passes it to the watch, the check and the copy. - L2 as a use-after-free: release clears the magic and removes the handle, and `free_dead_copies` frees only under the exclusive lock. With the two seq_cst fences, either the call's check sees the removal and stops, or the free sees `calls_copying` and skips. The `pin` case fails if the `calls_copying` test is taken out (the fixture's replay is always past the release). - L3: the call's sum is checked before each add. In `cmd_reserve_rec`, `used` stays at or below `CMD_SEG_MAX - OP_RESERVE` (cap is a power of two at most `CMD_SEG_MAX`, and the writes stay within what was reserved), so the new bound can't underflow and the doubling can't wrap. - L5 and L6: one place for the count and the array, and the row now says off unless set, with the Windows empty-value case. - L7 to L10: per-API `first` cases with the expected bytes built separately, a first read through a one-handle call, `bad` with a prefix that EndRecording never made, the real Initialize and Finalize, and `parse_compiler` (it is on main). - L11: the growth counts are on the log line, and nothing parses that line. - The default path's only new cost is an `mfence` in `free_dead_copies` when something is due, under a lock it already holds. That is negligible. - `CALL_AT_ONCE` puts 1 KiB on the stack, and a larger call falls back to main's loop. The test writes only to its own temporary folder and downloads nothing. **Blocking** (to change before merge) 1. `host/nvn_native.c:1586` (`free_dead_copies`) and `:1889`/`:1904` (`inline_recordings`): every free is skipped while any thread is inside a batched call. Nothing makes that count reach zero at a free: several job threads calling recordings back to back, as in the Market, can keep it above zero at each AddControlMemory and sweep. The held copies then grow with what the game releases, and on main they go once the replay passes them. Risks names this, and the "Still to test" Market run would only measure it. The epoch bound in Risks is one way to fix it. A simpler one removes the mechanism altogether: - phase 1: snapshot, `check_handle`, `called_size` and the sum, then `cmd_reserve_rec(r, all)` once; - phase 2, for each snapshot handle: `check_handle` again, then `inline_recording` (its `cmd_reserve_rec` returns at once when the room is there) and the copy. The check-to-copy window is then main's, without even the allocation in it. A handle the game released meanwhile stops the call as main would, and a bad handle still stops the call before anything is copied. `calls_copying`, the fences and the change to `free_dead_copies` all go. The second check is one lock-free probe per handle, small next to the memcpy. The `pin` case would then check that a handle released during the room-making stops the call (or still copies its live replacement), and that the frees aren't held. **Suggestions** (the author may take or leave) - `host/nvn_native.c:1586`: if `calls_copying` stays, its load wants `__ATOMIC_ACQUIRE` (or an acquire fence after it). The seq_cst fence comes before the load, so in C11 terms a call's memcpy reads are not ordered before the `pool_put` that follows a read of 0. x86 hides this, but the compiler is free to move the later code. - `host/nvn_native.c:2323`: `watch_draw_cmd = P(0)` is still a plain store, while the readers now use atomics. An `__atomic_store_n(..., __ATOMIC_RELAXED)` would make the L4 fix whole. It is a diagnostic only. **Questions** - With two A/B steps of the old `HOS_NVN_SEG_PEAK` showing no difference, what segment-growth rate in a real Market call would make this worth a switch? The log line's new counts, from one own-PC run with it on, would answer that before a farm run. **Testing:** the author ran the PR's own checks and the `--changed` selection on Windows (i7-9700, RTX 4060). The 9 failures also fail on main. It has not run in the game anywhere: AGENTS.md wants the author's own in-game run first, and the Test Farm is for hardware the author doesn't have. The @Beanstalk request (Hyrule Field, Linux NVIDIA and AMD, Windows Intel, Steam Deck) should wait for the change above, since it would measure code that changes. When it runs, it should also report the log line's live copies (MB) and peak host memory, on and off: that is the regression a batched call could cause. It should include Castle Town Market, where these calls are heaviest, and run more than one interleaved pass a side, so "p99 equal or better" has a spread to be judged against. CI is still pending. **Overlaps and merge order:** - https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2025 and https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2022 (both yours) rework `release_copies`, `free_dead_copies` and the sweep. Blocking 1's way leaves `free_dead_copies` alone and avoids that clash. - https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2050 (yours) splits `cmd_reserve_rec` into an inline fast path and a slow path, and the `CMD_SEG_MAX` check belongs in its slow path. Whichever merges second rebases onto the other. - https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1780 adds counts to the same log line, a textual conflict only. - The others listed touch other parts of the file, and the `switches.def` row is the usual textual conflict.
@ -1568,2 +1583,4 @@
const uint64_t done = rx_nvn_replayed();
if (done < dead_first) return;
__atomic_thread_fence(__ATOMIC_SEQ_CST);
if (__atomic_load_n(&calls_copying, __ATOMIC_RELAXED)) return;
Member

Blocking 1: while any batched call copies, every free is skipped, and nothing brings the count to zero at a free, so the held copies can grow without bound with the switch on. Simpler: reserve once, then check each handle again at its copy, as main does; then calls_copying and this check go. If it stays, this load wants __ATOMIC_ACQUIRE: the fence before it doesn't order the call's memcpy before the pool_put.

Blocking 1: while any batched call copies, every free is skipped, and nothing brings the count to zero at a free, so the held copies can grow without bound with the switch on. Simpler: reserve once, then check each handle again at its copy, as main does; then calls_copying and this check go. If it stays, this load wants __ATOMIC_ACQUIRE: the fence before it doesn't order the call's memcpy before the pool_put.
@ -1832,0 +1886,4 @@
size_t size[CALL_AT_ONCE], all = 0;
memcpy(hs, h, sizeof *hs * (size_t)n);
InterlockedIncrement64(&calls_reserved);
__atomic_fetch_add(&calls_copying, 1, __ATOMIC_RELAXED);
Member

Blocking 1: phase 2 can re-run check_handle on each snapshot handle before its copy (inline_recording's cmd_reserve_rec returns at once when the room is there). That keeps main's check-to-copy window without the gate on free_dead_copies.

Blocking 1: phase 2 can re-run check_handle on each snapshot handle before its copy (inline_recording's cmd_reserve_rec returns at once when the room is there). That keeps main's check-to-copy window without the gate on free_dead_copies.
siantm force-pushed perf/nvn-call-reserve from eac243608f
Some checks failed
Website / Website on Cloudflare (pull_request_target) Has been skipped
beanstalk/approval waiting for a BigBean's 👍 on the request
PR description / Description follows the template (pull_request_target) Successful in 4s
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
Website / Website on Cloudflare (pull_request) Has been cancelled
to 39fe40deff
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
Website / Website on Cloudflare (pull_request) Blocked by required conditions
Website / Website on Cloudflare (pull_request_target) Has been skipped
beanstalk/approval waiting for a BigBean's 👍 on the request
PR description / Description follows the template (pull_request_target) Successful in 6s
2026-11-21 11:03:03 +00:00
Compare
siantm changed title from WIP: perf(nvn): a call of several recordings makes room for all of them at once (HOS_NVN_CALL_RESERVE=1 to try it) to WIP: perf(nvn): a call of several recordings makes room for all of them at once (HOS_NVN_CALL_RESERVE=0 to disable) 2026-11-21 11:03:59 +00:00
Author
Contributor

Thank you for the review (#2023 (comment)). Pushed 39fe40de, rebased on main @ 9dd41326 (from b62932a9; git range-diff "=" for every commit, main's move touched none of its files): the test commit eb4d64f6 (fails on the code before the fix: the switch's first read answers 0 where 1 is expected, and the run stops there) and the fix 39fe40de. What ran is in the description's Tested (queue jobs fb-2023-l9 and fb-2023-h9); nothing has run in the game.

  • Blocking 1 (#2023 (comment), #2023 (comment)): done your way in 39fe40de. Phase 1 snapshots the array, checks and sizes each handle and makes the room once; phase 2 checks each snapshot handle again just before its copy and copies it with inline_recording (its reserve returns at once). calls_copying, the fences and the change to free_dead_copies are gone, so free_dead_copies is main's again. The pin case (eb4d64f6) releases the called recordings while the call makes its room: the AddControlMemory that follows frees them (nothing holds them), and the call stops at its second check with nothing copied, as main would; the array changed to another live recording during the room is still copied as checked.
  • Suggestion, acquire on the calls_copying load: moot, the count is gone.
  • Suggestion, watch_draw_cmd = P(0): done in 39fe40de: __atomic_store_n(..., __ATOMIC_RELAXED).
  • Default: HOS_NVN_CALL_RESERVE is on again (a kill switch, =0 is main's one at a time), the value this change proposes: docs/dev/standards.md (Switches) has a switch ship at its intended value from the first push, never off just because it is unmeasured. Measurements says "not measured in play yet"; if the A/B goes against it, it is turned off or dropped before this leaves WIP. The title says =0 to disable.
  • Question, the growth rate that makes it worth a switch: pending. It needs the log line's counts from an own-PC Market run with it on (unset) and with =0, which is in Still to test with the live copies (MB) and peak host memory; nothing was run in the game on this PC.
  • Testing and the farm: the Test Farm request above was for the earlier code and the earlier default, and was not started; the farm item in Still to test now names Kokiri Forest and Castle Town Market, unset against =0 against main, with live copies (MB) and peak host memory.
  • Overlaps: with free_dead_copies left as main has it, #2022 and #2025 no longer clash with this here; with #2050 whichever merges second rebases (the CMD_SEG_MAX check goes in its slow path).
  • BeanBot L2 (#2023 (comment)): this now follows the human review instead of a lifetime reference: each handle is checked again just before its copy, so the check-to-copy window is main's own and nothing defers a free.
Thank you for the review (https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2023#issuecomment-65678). Pushed 39fe40de, rebased on main @ 9dd41326 (from b62932a9; `git range-diff` "=" for every commit, main's move touched none of its files): the test commit eb4d64f6 (fails on the code before the fix: the switch's first read answers 0 where 1 is expected, and the run stops there) and the fix 39fe40de. What ran is in the description's Tested (queue jobs fb-2023-l9 and fb-2023-h9); nothing has run in the game. - **Blocking 1** (https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2023#issuecomment-65676, https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2023#issuecomment-65677): done your way in 39fe40de. Phase 1 snapshots the array, checks and sizes each handle and makes the room once; phase 2 checks each snapshot handle again just before its copy and copies it with `inline_recording` (its reserve returns at once). `calls_copying`, the fences and the change to `free_dead_copies` are gone, so `free_dead_copies` is main's again. The `pin` case (eb4d64f6) releases the called recordings while the call makes its room: the AddControlMemory that follows frees them (nothing holds them), and the call stops at its second check with nothing copied, as main would; the array changed to another live recording during the room is still copied as checked. - **Suggestion, acquire on the `calls_copying` load**: moot, the count is gone. - **Suggestion, `watch_draw_cmd = P(0)`**: done in 39fe40de: `__atomic_store_n(..., __ATOMIC_RELAXED)`. - **Default**: `HOS_NVN_CALL_RESERVE` is on again (a kill switch, `=0` is main's one at a time), the value this change proposes: docs/dev/standards.md (Switches) has a switch ship at its intended value from the first push, never off just because it is unmeasured. Measurements says "not measured in play yet"; if the A/B goes against it, it is turned off or dropped before this leaves WIP. The title says `=0 to disable`. - **Question, the growth rate that makes it worth a switch**: pending. It needs the log line's counts from an own-PC Market run with it on (unset) and with `=0`, which is in Still to test with the live copies (MB) and peak host memory; nothing was run in the game on this PC. - **Testing and the farm**: the Test Farm request above was for the earlier code and the earlier default, and was not started; the farm item in Still to test now names Kokiri Forest and Castle Town Market, unset against `=0` against main, with live copies (MB) and peak host memory. - **Overlaps**: with `free_dead_copies` left as main has it, #2022 and #2025 no longer clash with this here; with #2050 whichever merges second rebases (the `CMD_SEG_MAX` check goes in its slow path). - **BeanBot L2** (https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2023#issuecomment-64227): this now follows the human review instead of a lifetime reference: each handle is checked again just before its copy, so the check-to-copy window is main's own and nothing defers a free.
Author
Contributor

@Beanstalk This makes NVN CallCommands and CopyCommands of several recordings reserve their room once (host/nvn_native.c), on by default (HOS_NVN_CALL_RESERVE); HOS_NVN_CALL_RESERVE=0 turns it off. This head is on main 9dd41326: please compare with main at that merge base. Please start from the market-entrance save and play Castle Town Market, the heaviest scene for this, for three minutes, the PR against main on the same PC, on the PR's side with the switch unset and with HOS_NVN_CALL_RESERVE=0, with a picture compared with main's, on Linux with NVIDIA, Linux with AMD (RADV), Windows with Intel and the Steam Deck. The same picture, no crash, no FATAL line and no "not a live recording" line; unset, fewer segment growths and fewer MB copied in the recordings' log line than with it off, live copies (MB) and peak process memory no higher than with it off, and frame time p99 equal to main's or better. Please report that line.

@Beanstalk This makes NVN CallCommands and CopyCommands of several recordings reserve their room once (host/nvn_native.c), on by default (HOS_NVN_CALL_RESERVE); HOS_NVN_CALL_RESERVE=0 turns it off. This head is on main 9dd41326: please compare with main at that merge base. Please start from the market-entrance save and play Castle Town Market, the heaviest scene for this, for three minutes, the PR against main on the same PC, on the PR's side with the switch unset and with HOS_NVN_CALL_RESERVE=0, with a picture compared with main's, on Linux with NVIDIA, Linux with AMD (RADV), Windows with Intel and the Steam Deck. The same picture, no crash, no FATAL line and no "not a live recording" line; unset, fewer segment growths and fewer MB copied in the recordings' log line than with it off, live copies (MB) and peak process memory no higher than with it off, and frame time p99 equal to main's or better. Please report that line.
Member

@siantm only members of BigBeans can start the farm. One of them can approve this request by reacting 👍 to it or to this comment.

@siantm only members of `BigBeans` can start the farm. One of them can approve this request by reacting 👍 to it or to this comment.
Author
Contributor

Description: Risks now says that this conflicts with #1780 in the end-of-recording log line of nvnCommandBufferEndRecording (host/nvn_native.c), the overlap BeanBot pointed to (#issuecomment-64085), and nowhere else; whichever is merged first goes first and the other rebases onto it. No push.

Description: Risks now says that this conflicts with #1780 in the end-of-recording log line of `nvnCommandBufferEndRecording` (`host/nvn_native.c`), the overlap BeanBot pointed to ([#issuecomment-64085](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2023#issuecomment-64085)), and nowhere else; whichever is merged first goes first and the other rebases onto it. No push.
Author
Contributor

@Beanstalk One correction to my request 66182 above, for its picture point: please take each picture 5 s (300 frames at 60 fps) after the first frame whose picture is not a single uniform colour, with no input in between, and take the main-against-itself picture from the same point. A picture taken during the load's fade-in from black is not comparable: run 70269 on #2156 caught the fade in 3 of 4 starts.

@Beanstalk One correction to my request 66182 above, for its picture point: please take each picture 5 s (300 frames at 60 fps) after the first frame whose picture is not a single uniform colour, with no input in between, and take the main-against-itself picture from the same point. A picture taken during the load's fade-in from black is not comparable: run 70269 on #2156 caught the fade in 3 of 4 starts.
Member

@siantm only members of BigBeans can start the farm. One of them can approve this request by reacting 👍 to it or to this comment.

@siantm only members of `BigBeans` can start the farm. One of them can approve this request by reacting 👍 to it or to this comment.
Author
Contributor

@Beanstalk This replaces my request 66182 on this head and the corrections under it, in a form the farm can run: it cannot time a picture from the first frame that is not a uniform colour (its answer on #2131), so each picture here follows a fixed wait after the map event. This makes NVN CallCommands and CopyCommands of several recordings reserve their room once (host/nvn_native.c). Please start from the market-entrance save and take the picture 10 s (600 frames at 60 fps) after the map event that ends the load, a fixed wait with no input in between (the farm cannot time it from the first frame that is not a uniform colour), with a main-against-itself picture on the same PC from the same point; then, for frame times only, play Castle Town Market, the heaviest scene for this, for three minutes; at least two starts a side, interleaved, the PR against main on the same PC, on the PR's side unset (the default, on) and with HOS_NVN_CALL_RESERVE=0 (off), on Linux with an RTX 3080 Ti, Linux with an RX 6600 (RADV), Windows with an Arc B580 and the Steam Deck. The same picture as main within main's own difference from itself; with it unset, frame time p99 equal to main's or better, within the run-to-run spread, and equal to HOS_NVN_CALL_RESERVE=0 or better. The log must have no FATAL line and no "not a live recording" line, and no run may crash. Unset, the recordings' log line must show fewer segment growths and fewer MB copied than with HOS_NVN_CALL_RESERVE=0, and live copies (MB) and peak process memory no higher; please report that line.

@Beanstalk This replaces my request 66182 on this head and the corrections under it, in a form the farm can run: it cannot time a picture from the first frame that is not a uniform colour (its answer on #2131), so each picture here follows a fixed wait after the map event. This makes NVN CallCommands and CopyCommands of several recordings reserve their room once (host/nvn_native.c). Please start from the market-entrance save and take the picture 10 s (600 frames at 60 fps) after the map event that ends the load, a fixed wait with no input in between (the farm cannot time it from the first frame that is not a uniform colour), with a main-against-itself picture on the same PC from the same point; then, for frame times only, play Castle Town Market, the heaviest scene for this, for three minutes; at least two starts a side, interleaved, the PR against main on the same PC, on the PR's side unset (the default, on) and with HOS_NVN_CALL_RESERVE=0 (off), on Linux with an RTX 3080 Ti, Linux with an RX 6600 (RADV), Windows with an Arc B580 and the Steam Deck. The same picture as main within main's own difference from itself; with it unset, frame time p99 equal to main's or better, within the run-to-run spread, and equal to HOS_NVN_CALL_RESERVE=0 or better. The log must have no FATAL line and no "not a live recording" line, and no run may crash. Unset, the recordings' log line must show fewer segment growths and fewer MB copied than with HOS_NVN_CALL_RESERVE=0, and live copies (MB) and peak process memory no higher; please report that line.
Member

@siantm only members of BigBeans can start the farm. One of them can approve this request by reacting 👍 to it or to this comment.

@siantm only members of `BigBeans` can start the farm. One of them can approve this request by reacting 👍 to it or to this comment.
Author
Contributor

@dyst the in-game run your review (65678) found missing is in Measurements. It was one sitting on this PC: HOS_NVN_CALL_RESERVE=0 against unset in one runtime of 39fe40de, Kokiri Forest CPU-paced, 8 runs a side interleaved. No not a live recording line, FATAL or device lost came in any run.

  • The change's own figures, from the recordings' line in play:
    • With it on, about 12,700 calls of several recordings every 100,000 recordings were given their room at once.
    • The segments' growths copied 13 % fewer bytes: 426 against 373 MB every 100,000 recordings, every run apart, p = 0.0002. That is a few tens of KB a frame.
    • There were as many growths, 3,390 against 3,389 (p = 0.95). The description expected fewer growths too, and that did not come.
  • No line times the copies. The game's own code in the calm stretch, where these calls run, was 1.2 % lower but not shown (p = 0.21). Frame time and the tail are not shown either way.
  • The Market pair is spoiled: main's run took place while the PC was at its commit limit.

One sitting, so not called a gain yet; a second sitting is in Still to test.

@dyst the in-game run your review (65678) found missing is in Measurements. It was one sitting on this PC: `HOS_NVN_CALL_RESERVE=0` against unset in one runtime of 39fe40de, Kokiri Forest CPU-paced, 8 runs a side interleaved. No `not a live recording` line, FATAL or device lost came in any run. - The change's own figures, from the recordings' line in play: - With it on, about 12,700 calls of several recordings every 100,000 recordings were given their room at once. - The segments' growths copied 13 % fewer bytes: 426 against 373 MB every 100,000 recordings, every run apart, p = 0.0002. That is a few tens of KB a frame. - There were as many growths, 3,390 against 3,389 (p = 0.95). The description expected fewer growths too, and that did not come. - No line times the copies. The game's own code in the calm stretch, where these calls run, was 1.2 % lower but not shown (p = 0.21). Frame time and the tail are not shown either way. - The Market pair is spoiled: main's run took place while the PC was at its commit limit. One sitting, so not called a gain yet; a second sitting is in Still to test.
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
Website / Website on Cloudflare (pull_request) Blocked by required conditions
Website / Website on Cloudflare (pull_request_target) Has been skipped
beanstalk/approval waiting for a BigBean's 👍 on the request
PR description / Description follows the template (pull_request_target) Successful in 6s
This pull request is marked as a work in progress.
Some workflows are waiting to be reviewed.
This branch is out-of-date with the base branch
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'perf/nvn-call-reserve:siantm-perf/nvn-call-reserve'
git switch 'siantm-perf/nvn-call-reserve'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
4 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!2023
No description provided.