perf(host): NVN recordings' copies: the sweep's ticket read at retirement, segment size hints, frees outside the copy lock (HOS_NVN_REC_OLD=1 as before) #1812

Closed
GummiNaomi wants to merge 3 commits from GummiNaomi/Longshot:perf/nvn-recording-copies into main
Member

Summary

Longshot copies each command recording the game makes and frees those copies later. This PR changes the bookkeeping around those copies, and fixes a race that main has too.

The race: the sweep of overwritten copies read its ticket (the submits so far, held ones included) before it read the copies' marks. A producer could submit a copy at N + 1 and then overwrite its mark in between, so the sweep let the copy go at N, and the pool could hand its block out again while the replay still read it. main reads the same ticket under the copy lock, but still before the slice reads its marks, so the window there is smaller but present. The ticket is now retire_ticket(), read once the copy is seen dead: fences, then the held count, then pushed.

The bookkeeping, on top of that:

  • a command buffer's first segment starts at the size it needed last time, by guest address (seg_hints), instead of 64 KiB every frame;
  • dead copies and bucket nodes are freed once copy_lock is let go (frees / frees_run);
  • the sweep runs in batches of 128 buckets a hold of the lock, after EndRecording has let it go (sweep_slice), not inside its hold;
  • a called handle is prefetched (handle_prefetch, in check_handle, CallCommands and CopyCommands).

HOS_NVN_REC_OLD=1 restores the old bookkeeping (64 KiB first segments, frees under the lock, the slice inside EndRecording, no prefetch) and keeps the ticket fix.

Unchanged: the copies themselves are main's, byte for byte (24-byte prefix, pool class, bucket nodes: copy_prefix, rec_node, flatten, BeginRecording), the bytes the replay reads, the handles and the API. What the game sees is the same.

The result: measured at this head against its base on 4 and 16 cores, frame rate, frame tails, memory and the game threads' CPU are unchanged, within run-to-run spread. The ticket fix closes a use-after-free window present on main. Whether the bookkeeping without a measured gain is worth carrying is the reviewer's call.

The review of b8d2204b (futondestroyer) had two blocking points, both fixed: the sweep's ticket (above), and the copy's prefix, which had grown to 48 bytes (the bucket node inside it) even with HOS_NVN_REC_OLD=1, so a 65,504-byte recording's copy crossed into the 128 KiB class; the prefix and nodes are main's again, both ways.

#1780 (snaildev99) hands a half-full segment over as the handle (HOS_NVN_REC_HANDOFF): the same mechanism and rule as this PR's former end_copy, and only one can be on. This PR's hand-over is removed, since #1780's came first, is that one change behind its own switch, is measured at its own head, and ours never showed a gain. The remaining overlap with #1780 is text next to BeginRecording, EndRecording and flatten only; #1780's rec_end writes main's 24-byte prefix, which is the prefix here again, so either can merge first. #1811's submit accounting: this PR no longer changes what is submitted or when, only when the ticket is read.

Read first: retire_ticket, release_copies and sweep_buckets in host/nvn_native.c, then seg_hints, frees_run and sweep_slice, and tests/test_nvn_recording_copies.py. See #1780, #1811, #1553, #766.

Testing

Tested: Windows 11 Pro 26200, RTX 4070 SUPER (NVIDIA 617.42), Ryzen 9 9950X3D with SMT off, 32 GB, at this head 2763ba17: 12 stands in Castle Town's market (Measurements), 4 and 16 cores, with and without HOS_NVN_REC_OLD=1. No not a live recording line, no FATAL, no frame of 50 ms or more, and the picture as on main.
Checks, at 2763ba17:

  • tests/test_nvn_recording_copies.py passes on Windows (clang) and in WSL Ubuntu 24.04 (gcc 13.3, --cc gcc), both ways: the real recording code over stand-ins (eight frames of draw contexts calling cached model recordings, lifetimes, the sweep, six threads, nothing left at the end). sizes() checks a 65,504-byte recording's copy is 65,528 bytes in the 64 KiB class. tickets() pauses a sweep after its ticket while a producer submits the copy at N + 1 and overwrites its mark, and flushes a held submit between the ticket's two reads; neither copy may be freed with the replay at N. 7 broken variants are each caught: no hint, a hint that never shrinks, an early free, a batch from the wrong bucket, the ticket before the marks (main's order), pushed read first, a 48-byte prefix.
  • The new checks fail before the fix: against b8d2204b's source, tickets() and sizes() fail both ways. The fixture does not build against main's host/nvn_native.c (it cuts out functions this PR adds); main's ordering is the ticket-early variant, which it catches.
  • tests/test_hos_ab.py (the wired switch; sizes, tickets and six threads with it flipping every 16 reads: 127,016 reads, half of them old), tests/test_nvn_host_tables.py, tests/test_recording_log_handoff.py and tests/test_switch_table.py pass on Windows.
  • tests/run_all.py --changed 1780fbe0 in WSL Ubuntu 24.04: 30 pass, 10 fail, 6 skipped (no clang there). The 10 fail on main there too: test_crash_dialog, test_dev_ab, test_dev_packs, test_frame_overlap, test_hold_gpu, test_host_guest_writes, test_linux_pressure, test_present_queue_default, test_split_before_draw, test_vk_occlusion_queries. test_nvn_recording_copies and test_hos_ab, which run_all skips there, pass with --cc gcc.
  • Builds: on Windows, the builder's llvm-mingw build of this head (the measured build). No Linux build was done; on Linux only the checks above ran (the changed host code compiled and run by its tests with gcc 13.3 -Werror in WSL).

Still to test:

  • steamdeck: Castle Town's market for 3 minutes with HOS_AB=HOS_NVN_REC_OLD=1,3,60 RX_VK_FRAME_TRACE=1, then scripts/perf.py ab, expecting side 1 (the old bookkeeping) no faster and no not a live recording in the log (@Beanstalk steamdeck, Castle Town's market 3 minutes with HOS_AB=HOS_NVN_REC_OLD=1,3,60 and RX_VK_FRAME_TRACE=1)
  • linux, any GPU: Castle Town's market for 3 minutes, expecting no not a live recording, no FATAL and the picture as on main (@Beanstalk linux, Castle Town's market 3 minutes, the log and a screenshot)
  • Once #1780 is on main, this PR on top of it: the same Market stand, expecting no not a live recording and the frame rate as main's (@Beanstalk windows, Castle Town's market 3 minutes on this PR merged with #1780)

Measurements

Rebased: this head, 45159102, is 2763ba17 rebased onto main 89c3d21e with no conflicts; the numbers below are from 2763ba17 on its old base. At 45159102, tests/test_nvn_recording_copies.py, test_hos_ab.py, test_nvn_host_tables.py, test_recording_log_handoff.py and test_switch_table.py pass on Windows (clang), and host/nvn_native.c compiles syntax-only with the builder's flags.

Verdict: no change. Main, this PR and this PR with HOS_NVN_REC_OLD=1 are within each other's run-to-run spread at 4 and 16 cores, in mean frame rate, frame tails, process memory, the copies' memory and the game threads' CPU.

Setup: Windows 11 Pro 26200, RTX 4070 SUPER 12 GB (NVIDIA 617.42), Ryzen 9 9950X3D with SMT off, 32 GB. Castle Town's market (child), standing after a debug teleport from the kokiri-start save, 160 s; the control tool's test profile (1920x1080, headless); uncapped (HOS_FPS_MAX=1000); HOS_THREAD_TIMES=5; otherwise defaults. RX_VK_FRAME_TRACE=1; frames from 300 after the arrival to the end; fps from the summed frame times; process private bytes sampled just before the stop; the copies' MB from the last "recordings made" line; the game threads' CPU from the last 2 minutes of HOS_THREAD_TIMES. The game's affinity 0xF00 (4 cores) or 0xFFFF (16). Order main, on, off, off, on, main at each affinity (2 runs a side), all on 20 Nov 10:09-10:53. main @ 1780fbe0 is this branch's base, built 20 Nov; this PR @ 2763ba17 is one build for on and off ("off": HOS_NVN_REC_OLD=1).

Before: main @ 1780fbe0 After: this PR @ 2763ba17 After, HOS_NVN_REC_OLD=1: this PR @ 2763ba17
4 cores: fps (the two runs) 75.9, 77.0 75.8, 76.8 76.7, 77.6
4 cores: median / p99 / p99.9 ms (means) 12.84 / 16.95 / 20.16 12.84 / 17.25 / 20.35 12.69 / 17.05 / 21.11
16 cores: fps (the two runs) 90.6, 89.5 89.7, 90.4 89.8, 89.8
16 cores: median / p99 / p99.9 ms 11.04 / 13.42 / 15.36 11.04 / 13.59 / 16.03 11.06 / 13.54 / 15.37
private bytes at the end, MB (all 4 runs) 20,832-20,930 20,699-21,092 20,828-21,030
live copies, MB 22.9-24.8 22.6-24.1 22.8-23.7
game threads over 5 %, % of a core (4 / 16 cores) 331-332 / 333-334 329-333 / 331-335 329-330 / 339-343
rc20-c4-main-1   fps 75.9  med 12.95  p99 16.99  p99.9 20.50  max 29.1  priv 20903 MB
rc20-c4-on-2     fps 75.8  med 12.95  p99 17.06  p99.9 20.65  max 29.1  priv 20765 MB
rc20-c4-off-3    fps 76.7  med 12.75  p99 17.39  p99.9 22.17  max 49.4  priv 20929 MB
rc20-c4-off-4    fps 77.6  med 12.63  p99 16.70  p99.9 20.04  max 27.5  priv 21030 MB
rc20-c4-on-5     fps 76.8  med 12.74  p99 17.45  p99.9 20.05  max 27.3  priv 20699 MB
rc20-c4-main-6   fps 77.0  med 12.73  p99 16.91  p99.9 19.81  max 30.3  priv 20832 MB
rc20-c16-main-1  fps 90.6  med 10.97  p99 13.32  p99.9 15.32  max 24.1  priv 20862 MB
rc20-c16-on-2    fps 89.7  med 11.06  p99 13.69  p99.9 16.41  max 29.4  priv 20962 MB
rc20-c16-off-3   fps 89.8  med 11.07  p99 13.49  p99.9 15.08  max 24.1  priv 20937 MB
rc20-c16-off-4   fps 89.8  med 11.05  p99 13.60  p99.9 15.65  max 26.4  priv 20828 MB
rc20-c16-on-5    fps 90.4  med 11.01  p99 13.49  p99.9 15.65  max 25.2  priv 21092 MB
rc20-c16-main-6  fps 89.5  med 11.11  p99 13.52  p99.9 15.40  max 23.5  priv 20930 MB

The earlier start-to-start numbers on 54a42715 (62.4 to 58.8 and 60.1 to 64.5 fps at 2560x1440 with other experimental switches) were within their own spread and are replaced by these. Not measured: the copy lock's wait time itself (Tracy was not used), Linux, the Steam Deck.

HOS_NVN_REC_OLD (new, a kill switch, its row in gpu/vk/switches.def; read through hos_ab_value, so HOS_AB can flip it) ships unset: the new bookkeeping. The measurements above find no difference either way, so unset is not chosen for speed; =1 is for a recording problem, and keeps the ticket fix.

Risks

What could break: a copy freed too early would show as a wrong or missing draw or a crash in the replay. The ticket is now read later than on main, never earlier, so a copy is freed later if anything. The test covers the race deterministically and runs six threads both ways and under flips. The frees and the sweep run in a different place and order than on main. Not run: Linux or the Steam Deck in the game, this PR together with #1780 or #1811. Turning it off: HOS_NVN_REC_OLD=1 (the ticket fix stays); a revert is enough. After updating: nothing changes for saves, longshot_options.ini or the caches; no cost measured (Measurements).

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit. (Rebased onto main 89c3d21e as 45159102, no conflicts.)
  • 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). (tests/run_all.py --changed 1780fbe0 in WSL, its 10 failures main's own there, named in Testing; the PR's own checks on Windows.)
  • 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 fix: a game-free test that fails on main and passes here. (tickets() in tests/test_nvn_recording_copies.py: main's order, the ticket read before the marks, is its ticket-early variant, caught; it fails both ways on this PR's first head b8d2204b and passes here.)
  • A switch added or changed: it ships at the default the measurements chose, with its row in gpu/vk/switches.def. (HOS_NVN_REC_OLD, unset by default; the measurements found no difference either way.)
  • A check under tests/ that reads changed source is updated, not weakened.
  • Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. (Built on Windows: the builder's llvm-mingw build of 2763ba17, the measured build. On Linux only checks: tests/test_nvn_recording_copies.py and tests/test_hos_ab.py compile the changed host/nvn_native.c code with gcc 13.3 -Werror in WSL Ubuntu 24.04 and pass, and the --changed suite there. No Linux build was done.)
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

Ready to merge

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

🤖 Generated with Claude Code

## Summary Longshot copies each command recording the game makes and frees those copies later. This PR changes the bookkeeping around those copies, and fixes a race that main has too. The race: the sweep of overwritten copies read its ticket (the submits so far, held ones included) before it read the copies' marks. A producer could submit a copy at N + 1 and then overwrite its mark in between, so the sweep let the copy go at N, and the pool could hand its block out again while the replay still read it. main reads the same ticket under the copy lock, but still before the slice reads its marks, so the window there is smaller but present. The ticket is now `retire_ticket()`, read once the copy is seen dead: fences, then the held count, then pushed. The bookkeeping, on top of that: - a command buffer's first segment starts at the size it needed last time, by guest address (`seg_hints`), instead of 64 KiB every frame; - dead copies and bucket nodes are freed once `copy_lock` is let go (`frees` / `frees_run`); - the sweep runs in batches of 128 buckets a hold of the lock, after EndRecording has let it go (`sweep_slice`), not inside its hold; - a called handle is prefetched (`handle_prefetch`, in `check_handle`, CallCommands and CopyCommands). `HOS_NVN_REC_OLD=1` restores the old bookkeeping (64 KiB first segments, frees under the lock, the slice inside EndRecording, no prefetch) and keeps the ticket fix. Unchanged: the copies themselves are main's, byte for byte (24-byte prefix, pool class, bucket nodes: `copy_prefix`, `rec_node`, `flatten`, BeginRecording), the bytes the replay reads, the handles and the API. What the game sees is the same. The result: measured at this head against its base on 4 and 16 cores, frame rate, frame tails, memory and the game threads' CPU are unchanged, within run-to-run spread. The ticket fix closes a use-after-free window present on main. Whether the bookkeeping without a measured gain is worth carrying is the reviewer's call. The review of b8d2204b (futondestroyer) had two blocking points, both fixed: the sweep's ticket (above), and the copy's prefix, which had grown to 48 bytes (the bucket node inside it) even with `HOS_NVN_REC_OLD=1`, so a 65,504-byte recording's copy crossed into the 128 KiB class; the prefix and nodes are main's again, both ways. #1780 (snaildev99) hands a half-full segment over as the handle (`HOS_NVN_REC_HANDOFF`): the same mechanism and rule as this PR's former `end_copy`, and only one can be on. This PR's hand-over is removed, since #1780's came first, is that one change behind its own switch, is measured at its own head, and ours never showed a gain. The remaining overlap with #1780 is text next to BeginRecording, EndRecording and `flatten` only; #1780's `rec_end` writes main's 24-byte prefix, which is the prefix here again, so either can merge first. #1811's submit accounting: this PR no longer changes what is submitted or when, only when the ticket is read. Read first: `retire_ticket`, `release_copies` and `sweep_buckets` in `host/nvn_native.c`, then `seg_hints`, `frees_run` and `sweep_slice`, and `tests/test_nvn_recording_copies.py`. See #1780, #1811, #1553, #766. ## Testing **Tested:** Windows 11 Pro 26200, RTX 4070 SUPER (NVIDIA 617.42), Ryzen 9 9950X3D with SMT off, 32 GB, at this head 2763ba17: 12 stands in Castle Town's market (Measurements), 4 and 16 cores, with and without `HOS_NVN_REC_OLD=1`. No `not a live recording` line, no FATAL, no frame of 50 ms or more, and the picture as on main. Checks, at 2763ba17: - `tests/test_nvn_recording_copies.py` passes on Windows (clang) and in WSL Ubuntu 24.04 (gcc 13.3, `--cc gcc`), both ways: the real recording code over stand-ins (eight frames of draw contexts calling cached model recordings, lifetimes, the sweep, six threads, nothing left at the end). `sizes()` checks a 65,504-byte recording's copy is 65,528 bytes in the 64 KiB class. `tickets()` pauses a sweep after its ticket while a producer submits the copy at N + 1 and overwrites its mark, and flushes a held submit between the ticket's two reads; neither copy may be freed with the replay at N. 7 broken variants are each caught: no hint, a hint that never shrinks, an early free, a batch from the wrong bucket, the ticket before the marks (main's order), pushed read first, a 48-byte prefix. - The new checks fail before the fix: against b8d2204b's source, `tickets()` and `sizes()` fail both ways. The fixture does not build against main's `host/nvn_native.c` (it cuts out functions this PR adds); main's ordering is the `ticket-early` variant, which it catches. - `tests/test_hos_ab.py` (the wired switch; `sizes`, `tickets` and six threads with it flipping every 16 reads: 127,016 reads, half of them old), `tests/test_nvn_host_tables.py`, `tests/test_recording_log_handoff.py` and `tests/test_switch_table.py` pass on Windows. - `tests/run_all.py --changed 1780fbe0` in WSL Ubuntu 24.04: 30 pass, 10 fail, 6 skipped (no clang there). The 10 fail on main there too: `test_crash_dialog`, `test_dev_ab`, `test_dev_packs`, `test_frame_overlap`, `test_hold_gpu`, `test_host_guest_writes`, `test_linux_pressure`, `test_present_queue_default`, `test_split_before_draw`, `test_vk_occlusion_queries`. `test_nvn_recording_copies` and `test_hos_ab`, which run_all skips there, pass with `--cc gcc`. - Builds: on Windows, the builder's llvm-mingw build of this head (the measured build). No Linux build was done; on Linux only the checks above ran (the changed host code compiled and run by its tests with gcc 13.3 `-Werror` in WSL). **Still to test:** - steamdeck: Castle Town's market for 3 minutes with `HOS_AB=HOS_NVN_REC_OLD=1,3,60 RX_VK_FRAME_TRACE=1`, then `scripts/perf.py ab`, expecting side 1 (the old bookkeeping) no faster and no `not a live recording` in the log (@Beanstalk steamdeck, Castle Town's market 3 minutes with HOS_AB=HOS_NVN_REC_OLD=1,3,60 and RX_VK_FRAME_TRACE=1) - linux, any GPU: Castle Town's market for 3 minutes, expecting no `not a live recording`, no FATAL and the picture as on main (@Beanstalk linux, Castle Town's market 3 minutes, the log and a screenshot) - Once #1780 is on main, this PR on top of it: the same Market stand, expecting no `not a live recording` and the frame rate as main's (@Beanstalk windows, Castle Town's market 3 minutes on this PR merged with #1780) ## Measurements **Rebased:** this head, 45159102, is 2763ba17 rebased onto main 89c3d21e with no conflicts; the numbers below are from 2763ba17 on its old base. At 45159102, `tests/test_nvn_recording_copies.py`, `test_hos_ab.py`, `test_nvn_host_tables.py`, `test_recording_log_handoff.py` and `test_switch_table.py` pass on Windows (clang), and `host/nvn_native.c` compiles syntax-only with the builder's flags. **Verdict:** no change. Main, this PR and this PR with `HOS_NVN_REC_OLD=1` are within each other's run-to-run spread at 4 and 16 cores, in mean frame rate, frame tails, process memory, the copies' memory and the game threads' CPU. Setup: Windows 11 Pro 26200, RTX 4070 SUPER 12 GB (NVIDIA 617.42), Ryzen 9 9950X3D with SMT off, 32 GB. Castle Town's market (child), standing after a debug teleport from the `kokiri-start` save, 160 s; the control tool's `test` profile (1920x1080, headless); uncapped (`HOS_FPS_MAX=1000`); `HOS_THREAD_TIMES=5`; otherwise defaults. `RX_VK_FRAME_TRACE=1`; frames from 300 after the arrival to the end; fps from the summed frame times; process private bytes sampled just before the stop; the copies' MB from the last "recordings made" line; the game threads' CPU from the last 2 minutes of `HOS_THREAD_TIMES`. The game's affinity 0xF00 (4 cores) or 0xFFFF (16). Order main, on, off, off, on, main at each affinity (2 runs a side), all on 20 Nov 10:09-10:53. main @ 1780fbe0 is this branch's base, built 20 Nov; this PR @ 2763ba17 is one build for on and off ("off": `HOS_NVN_REC_OLD=1`). | | Before: main @ 1780fbe0 | After: this PR @ 2763ba17 | After, `HOS_NVN_REC_OLD=1`: this PR @ 2763ba17 | |---|---|---|---| | 4 cores: fps (the two runs) | 75.9, 77.0 | 75.8, 76.8 | 76.7, 77.6 | | 4 cores: median / p99 / p99.9 ms (means) | 12.84 / 16.95 / 20.16 | 12.84 / 17.25 / 20.35 | 12.69 / 17.05 / 21.11 | | 16 cores: fps (the two runs) | 90.6, 89.5 | 89.7, 90.4 | 89.8, 89.8 | | 16 cores: median / p99 / p99.9 ms | 11.04 / 13.42 / 15.36 | 11.04 / 13.59 / 16.03 | 11.06 / 13.54 / 15.37 | | private bytes at the end, MB (all 4 runs) | 20,832-20,930 | 20,699-21,092 | 20,828-21,030 | | live copies, MB | 22.9-24.8 | 22.6-24.1 | 22.8-23.7 | | game threads over 5 %, % of a core (4 / 16 cores) | 331-332 / 333-334 | 329-333 / 331-335 | 329-330 / 339-343 | ``` rc20-c4-main-1 fps 75.9 med 12.95 p99 16.99 p99.9 20.50 max 29.1 priv 20903 MB rc20-c4-on-2 fps 75.8 med 12.95 p99 17.06 p99.9 20.65 max 29.1 priv 20765 MB rc20-c4-off-3 fps 76.7 med 12.75 p99 17.39 p99.9 22.17 max 49.4 priv 20929 MB rc20-c4-off-4 fps 77.6 med 12.63 p99 16.70 p99.9 20.04 max 27.5 priv 21030 MB rc20-c4-on-5 fps 76.8 med 12.74 p99 17.45 p99.9 20.05 max 27.3 priv 20699 MB rc20-c4-main-6 fps 77.0 med 12.73 p99 16.91 p99.9 19.81 max 30.3 priv 20832 MB rc20-c16-main-1 fps 90.6 med 10.97 p99 13.32 p99.9 15.32 max 24.1 priv 20862 MB rc20-c16-on-2 fps 89.7 med 11.06 p99 13.69 p99.9 16.41 max 29.4 priv 20962 MB rc20-c16-off-3 fps 89.8 med 11.07 p99 13.49 p99.9 15.08 max 24.1 priv 20937 MB rc20-c16-off-4 fps 89.8 med 11.05 p99 13.60 p99.9 15.65 max 26.4 priv 20828 MB rc20-c16-on-5 fps 90.4 med 11.01 p99 13.49 p99.9 15.65 max 25.2 priv 21092 MB rc20-c16-main-6 fps 89.5 med 11.11 p99 13.52 p99.9 15.40 max 23.5 priv 20930 MB ``` The earlier start-to-start numbers on 54a42715 (62.4 to 58.8 and 60.1 to 64.5 fps at 2560x1440 with other experimental switches) were within their own spread and are replaced by these. Not measured: the copy lock's wait time itself (Tracy was not used), Linux, the Steam Deck. `HOS_NVN_REC_OLD` (new, a kill switch, its row in `gpu/vk/switches.def`; read through `hos_ab_value`, so `HOS_AB` can flip it) ships unset: the new bookkeeping. The measurements above find no difference either way, so unset is not chosen for speed; `=1` is for a recording problem, and keeps the ticket fix. ## Risks What could break: a copy freed too early would show as a wrong or missing draw or a crash in the replay. The ticket is now read later than on main, never earlier, so a copy is freed later if anything. The test covers the race deterministically and runs six threads both ways and under flips. The frees and the sweep run in a different place and order than on main. Not run: Linux or the Steam Deck in the game, this PR together with #1780 or #1811. Turning it off: `HOS_NVN_REC_OLD=1` (the ticket fix stays); a revert is enough. After updating: nothing changes for saves, `longshot_options.ini` or the caches; no cost measured (Measurements). ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. (Rebased onto main 89c3d21e as 45159102, no conflicts.) - [x] Tested on my own PC, in the game for a change the game runs, as Testing says. - [x] `mise run test` passes (any failure that also fails on `main` is named). (`tests/run_all.py --changed 1780fbe0` in WSL, its 10 failures main's own there, named in Testing; the PR's own checks on Windows.) - [x] Measured against `main`, or Measurements says why there is nothing to measure. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [x] A fix: a game-free test that fails on `main` and passes here. (`tickets()` in `tests/test_nvn_recording_copies.py`: main's order, the ticket read before the marks, is its `ticket-early` variant, caught; it fails both ways on this PR's first head b8d2204b and passes here.) - [x] A switch added or changed: it ships at the default the measurements chose, with its row in `gpu/vk/switches.def`. (`HOS_NVN_REC_OLD`, unset by default; the measurements found no difference either way.) - [x] A check under `tests/` that reads changed source is updated, not weakened. - [ ] Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. (Built on Windows: the builder's llvm-mingw build of 2763ba17, the measured build. On Linux only checks: `tests/test_nvn_recording_copies.py` and `tests/test_hos_ab.py` compile the changed `host/nvn_native.c` code with gcc 13.3 `-Werror` in WSL Ubuntu 24.04 and pass, and the `--changed` suite there. No Linux build was done.) - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
perf(host): NVN command buffers' segments and recordings' copies made cheaper (HOS_NVN_REC_OLD=1 as before)
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 13s
CI / Workflow lint (actionlint) (pull_request) Successful in 20s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 19s
Third-party parts / As their notes say (pull_request) Successful in 22s
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Failing after 5s
df5d7aed1e
The game makes its draw contexts' command buffers anew every frame at the same addresses, and each one's
segment grew again from 64 KiB, its records copied at every doubling; then EndRecording copied the whole
recording once more into the handle's block. Now a command buffer's first segment starts at the size its
last life needed (by guest address), and a recording that fills over half of its segment becomes its
handle in place (the same pool block size the copy would take). The copies' bucket entries live in the
copies' own prefixes instead of a block malloc'ed for each, dead copies go back to the pool after
copy_lock is let go, a sweep's slice takes the lock 128 buckets at a time once EndRecording has let it
go, and a called handle's prefix is prefetched while its liveness is looked up. What the game sees is
the same either way. The sweep's and the report's log lines are still written once copy_lock and the
virtual core are let go. HOS_NVN_REC_OLD is read through hos_ab_value, so HOS_AB can compare the two.

Assisted-by: Claude Code
Co-Authored-By: Claude Opus 5.5 <[email protected]>
futondestroyer left a comment

Recommendation: Request changes. Copy retirement can use a completion watermark older than a submit that still references the recording.

Does it help: Unproven. GummiNaomi's earlier four-core headless comparisons on 54a42715 with companion changes went in opposite directions, 62.4 to 58.8 and 60.1 to 64.5 FPS. The exact published head is reported unbuilt.
Other systems: The new default runs across OSes and changes recording ownership and allocation size. Linux/Deck and exact-head build/game evidence are missing.
Switches: HOS_NVN_REC_OLD=1 restores portions of the previous path. It leaves the larger prefix and intrusive bookkeeping in use.
Reviewed: df5d7aed against 0de25c3e, with exact Graphify maps and source verification. Read copy allocation, submit accounting, control marks, retirement, and tests. Nothing run.
Fixed in this review: Nothing.
Checked and fine: The retirement pool has a completion gate. Its input must cover every submit that still owns the copy.

Blocking

  1. host/nvn_native.c:1753–1756,1618: the sliced sweep takes the submitted-plus-held watermark before acquiring the copy lock. While it waits, a producer can publish/submit a handle at N+1 and overwrite its control mark. The sweep sees the overwritten mark but retires it at N; the pool can reuse that copy while replay still needs it. Tie the retire ticket to an ordering point at actual retirement that covers preceding submits and held work. Add a deterministic paused-sweep, later-submit and overwritten-mark test.
  2. host/nvn_native.c:1365–1372,1483,1792: the copy prefix grows from 24 to 48 bytes even with the rollback enabled. A 65,504-byte recording crosses the 64 KiB pool class. Label the rollback as partial and compare exact main/off/on before making this the default, including allocation/RAM, contention and frame tails.

Testing: Rebase, build the exact candidate and replace the historical mixed comparison with matched Windows and Linux evidence. The head's description and Guide screenshots checks are red, and source checks were skipped.
Overlaps and merge order: Coordinate first with #1780, which also changes EndRecording ownership. Choose one handoff and rebase the remaining independent changes. Reconcile submit accounting with #1811 before testing them together.

**Recommendation: Request changes.** Copy retirement can use a completion watermark older than a submit that still references the recording. **Does it help:** Unproven. GummiNaomi's earlier four-core headless comparisons on 54a42715 with companion changes went in opposite directions, 62.4 to 58.8 and 60.1 to 64.5 FPS. The exact published head is reported unbuilt. **Other systems:** The new default runs across OSes and changes recording ownership and allocation size. Linux/Deck and exact-head build/game evidence are missing. **Switches:** HOS_NVN_REC_OLD=1 restores portions of the previous path. It leaves the larger prefix and intrusive bookkeeping in use. **Reviewed:** df5d7aed against 0de25c3e, with exact Graphify maps and source verification. Read copy allocation, submit accounting, control marks, retirement, and tests. Nothing run. **Fixed in this review:** Nothing. **Checked and fine:** The retirement pool has a completion gate. Its input must cover every submit that still owns the copy. **Blocking** 1. `host/nvn_native.c:1753–1756,1618`: the sliced sweep takes the submitted-plus-held watermark before acquiring the copy lock. While it waits, a producer can publish/submit a handle at N+1 and overwrite its control mark. The sweep sees the overwritten mark but retires it at N; the pool can reuse that copy while replay still needs it. Tie the retire ticket to an ordering point at actual retirement that covers preceding submits and held work. Add a deterministic paused-sweep, later-submit and overwritten-mark test. 2. `host/nvn_native.c:1365–1372,1483,1792`: the copy prefix grows from 24 to 48 bytes even with the rollback enabled. A 65,504-byte recording crosses the 64 KiB pool class. Label the rollback as partial and compare exact main/off/on before making this the default, including allocation/RAM, contention and frame tails. **Testing:** Rebase, build the exact candidate and replace the historical mixed comparison with matched Windows and Linux evidence. The head's description and Guide screenshots checks are red, and source checks were skipped. **Overlaps and merge order:** Coordinate first with https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1780, which also changes EndRecording ownership. Choose one handoff and rebase the remaining independent changes. Reconcile submit accounting with https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1811 before testing them together.
@ -1349,0 +1362,4 @@
exclusively (~98 recordings a frame in the Market, 4 cores, 18 Nov). A command buffer's segment keeps room for it at its
start (REC_HEAD), so that the segment itself can become the copy (end_copy). */
#define COPY_MAGIC 0x59504f43444d43ull /* "CMDCOPY" */
typedef struct copy_prefix {
Member

The larger prefix remains in the old-switch arm and can cross a pool class. Compare against exact main as well as both candidate settings.

The larger prefix remains in the old-switch arm and can cross a pool class. Compare against exact main as well as both candidate settings.
@ -1675,0 +1750,4 @@
size_t swept = 0;
for (unsigned s = 0; s < SWEEP_SLICE; s += SWEEP_BATCH) {
const unsigned count = SWEEP_SLICE - s < SWEEP_BATCH ? SWEEP_SLICE - s : SWEEP_BATCH;
const uint64_t after = rx_nvn_pushed() + held_count();
Member

The watermark predates copy_lock acquisition and can miss a later submit of a now-retired handle. Tie retirement to a watermark covering actual retired handles and held submits.

The watermark predates copy_lock acquisition and can miss a later submit of a now-retired handle. Tie retirement to a watermark covering actual retired handles and held submits.
GummiNaomi force-pushed perf/nvn-recording-copies from df5d7aed1e
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 13s
CI / Workflow lint (actionlint) (pull_request) Successful in 20s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 19s
Third-party parts / As their notes say (pull_request) Successful in 22s
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Failing after 5s
to b8d2204b4a
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 12s
CI / Workflow lint (actionlint) (pull_request) Successful in 18s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 16s
Third-party parts / As their notes say (pull_request) Successful in 24s
PR description / Description follows the template (pull_request_target) Failing after 9s
CI / Website build and checks (pull_request) Has been cancelled
2026-11-20 07:46:38 +00:00
Compare
Owner

@Beanstalk

@Beanstalk
Member

@HumanBean the PR got a new push (b8d2204) after your comment. Review it and approve again.

@HumanBean the PR got a new push (`b8d2204`) after your comment. Review it and approve again.
Review of #1812 (futondestroyer):

1. The sweep took its ticket (the submits made so far, held ones too) before a batch had copy_lock and had
read its marks. A producer could submit a copy at N + 1 and then overwrite its mark meanwhile: the sweep saw the
overwritten mark and let the copy go at N, and the pool could hand its block out again while the replay still read
it. The ticket is now read at the retirement (retire_ticket): in a sweep after every mark of the batch was read,
in release_copies once AddControlMemory has the lock; the held count first, then pushed, so a flush between the
two reads counts its submits once or twice, never not at all. main read it before the marks as well (in the same
hold of the lock); both ways get the fix.

2. The copy's prefix grew from 24 to 48 bytes (the bucket node inside it) even with HOS_NVN_REC_OLD=1, so a
65,504-byte recording's copy crossed into the 128 KiB pool class. The prefix and the bucket nodes are main's
again, either way. The hand-over of a full segment as its handle (end_copy) is dropped from this PR: it is the
same mechanism as #1780's (HOS_NVN_REC_HANDOFF, the same half-full rule), which came first and is measured at its
own head; this PR keeps what is independent of it: the size hints, the dead copies and nodes freed once copy_lock
is let go, the sweep in batches outside EndRecording's hold, the handle prefetch.

tests/test_nvn_recording_copies.py: a sweep paused at its ticket while a producer submits the copy at N + 1 and
overwrites its mark, and paused between the ticket's two reads while a held submit naming the copy is flushed:
neither copy is freed with the replay at N (both fail on b8d2204b's source, both modes); a 65,504-byte recording's
copy is 65,528 bytes in the 64 KiB class (fails on b8d2204b); new broken variants: the ticket before the marks,
pushed read before held, a 48-byte prefix.

Assisted-by: Claude Code
Co-Authored-By: Claude Opus 5.5 <[email protected]>
test(host): the recording copies' checks build with gcc as well
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 7s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 11s
CI / Workflow lint (actionlint) (pull_request) Successful in 11s
Third-party parts / As their notes say (pull_request) Successful in 12s
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Failing after 5s
beanstalk/approval approved by GummiNaomi (reviewed)
beanstalk/steamdeck 0/1 pass, 0 running, 2 queued
beanstalk/linux 0/1 pass, 1 running, 0 queued
CI / Website build and checks (pull_request) Has been cancelled
2763ba174b
The fixture's rx_nvn_pushed and rx_nvn_replayed are not static (rx_nvn.h declares them), and gcc 13 is told not to
warn of the memsets of a slot or an object that an inlined lookup may leave NULL (-Wno-array-bounds,
-Wno-stringop-overflow, gcc only). Both checks were skipped on Linux before (no clang there); they now pass with
gcc 13.3 on WSL Ubuntu 24.04 and with clang on Windows.

Assisted-by: Claude Code
Co-Authored-By: Claude Opus 5.5 <[email protected]>
GummiNaomi changed title from perf(host): NVN command buffers' segments and recordings' copies made cheaper (HOS_NVN_REC_OLD=1 as before) to perf(host): NVN recordings' copies: the sweep's ticket read at retirement, segment size hints, frees outside the copy lock (HOS_NVN_REC_OLD=1 as before) 2026-11-20 10:56:41 +00:00
Author
Member

Thanks, both points were right. New head: 2763ba17 (66fb7c1c is the fix and 2763ba17 makes the test build with gcc).

1. The sweep's ticket was read too early. This was real, and main has it too. main read rx_nvn_pushed() + held_count() under the lock but before the slice read its marks, so the window was smaller but there. In host/nvn_native.c the ticket is now retire_ticket(), read where the copy is actually retired:

  • sweep_buckets reads every mark of its batch first, unlinks the copies whose marks were overwritten, and only then reads the ticket and lets them go.
  • release_copies reads the ticket inside its hold of copy_lock, after the AddControlMemory call that retires the copies.
  • The held count is read before pushed, with fences around the two reads. held_flush counts its submits up in pushed before it clears the held count, so a flush between the two reads counts those submits once or twice, never zero times. The other order (and C's unspecified order of the old a() + b()) could miss them.

Both ways (HOS_NVN_REC_OLD unset and =1) get the fix.

Test: tests/test_nvn_recording_copies.py, tickets(). The stubs rx_nvn_pushed and held_count have a pause point, which makes two cases deterministic:

  • (a) The sweep is paused after reading its ticket. Meanwhile a producer submits the copy at N + 1 and then overwrites its mark.
  • (b) A held submit names the copy, the game overwrites its mark, and the flush runs between the ticket's two reads.

In both cases the copy must still be on the dead list, with its bytes counted, when the replay is at N. It must be freed once the replay has passed its submit.

Before and after:

  • Against b8d2204b's nvn_native.c, (a) fails both ways: the copy is freed with the replay at N. (I ran the new fixture with only the take_due/node helpers adapted to that head's names.)
  • Two broken variants of the new code are caught: ticket-early (b8d2204b's expression before the marks) by (a), and pushed-first by (b).

2. The prefix grew from 24 to 48 bytes even with the rollback. Fixed at the root: copy_prefix is main's 24 bytes again, and the bucket nodes are main's rec_node, both ways. So a copy's block is byte for byte main's, and HOS_NVN_REC_OLD=1 is no longer partial.

Test: sizes() records a 65,504-byte recording and requires a 65,528-byte copy in the 64 KiB class, both ways. It fails on b8d2204b both ways; the prefix-48 broken variant is caught.

#1780. I read its diff at 620f3067. Its rec_begin / rec_end hand a half-full segment over as the handle, which is the same mechanism and the same rule as this PR's end_copy. Only one of them can be on. #1780's should win:

  • it came first;
  • it is that one change behind its own switch (HOS_NVN_REC_HANDOFF);
  • it is measured at its own head (+4.4 % standing in the Market on main a433db32);
  • this PR's hand-over never showed a gain.

So end_copy and the REC_HEAD room are gone from this PR. What is left is independent of it:

  • segment size hints by guest address;
  • dead copies and nodes freed once copy_lock is let go;
  • the sweep in 128-bucket batches outside EndRecording's hold;
  • the handle prefetch;
  • the ticket fix.

Either PR can merge first. The only overlap left is text next to BeginRecording, EndRecording and flatten, with no shared semantics: #1780's rec_end writes main's 24-byte prefix, and that is the prefix here again.

#1811. This PR no longer changes what is submitted or when. It only moves the ticket read later, so it is reconciled with #1811 by construction. They have not been tested together.

Does it help? No. Measured at exact heads: base main 1780fbe0 (this branch's base) and the PR at 2763ba17, with on and off (HOS_NVN_REC_OLD=1) from the same build. Setup:

  • Windows 11, RTX 4070 SUPER (617.42), Ryzen 9 9950X3D with SMT off.
  • Market_Child, standing still after a teleport from kokiri-start, 160 s, headless at 1920x1080, HOS_FPS_MAX=1000.
  • Frames from 300 after arrival to the end.
  • Runs in the order M ON OFF OFF ON M at each affinity.
main 1780fbe0 PR on PR off
4 cores (0xF00): fps, the two runs 75.9, 77.0 75.8, 76.8 76.7, 77.6
4 cores: p99 / p99.9 ms (means) 16.95 / 20.16 17.25 / 20.35 17.05 / 21.11
16 cores (0xFFFF): fps 90.6, 89.5 89.7, 90.4 89.8, 89.8
16 cores: p99 / p99.9 ms 13.42 / 15.36 13.59 / 16.03 13.54 / 15.37
private bytes at the end (MB) 20,832-20,930 20,699-21,092 20,828-21,030
live copies (MB, last 50k line) 22.9-24.8 22.6-24.1 22.8-23.7

Every difference is inside the spread of the same arm's two runs, frame tails included. No not a live recording, no FATAL and no frame of 50 ms or more.

The game threads' CPU over the last 2 minutes (HOS_THREAD_TIMES=5, threads over 5 %) is the same within about 2 % in every arm, so I can't show less contention either. The copy lock's wait was not measured directly.

What this PR can claim now is the ticket fix, a race main has too. Otherwise it is bookkeeping with no measured effect. If you'd rather not carry that, I can split the ticket fix into its own small PR on main and close this one.

Checks at 2763ba17:

  • Windows (clang): test_nvn_recording_copies (both ways, 7 broken variants caught), test_hos_ab (including the flips run, which now also runs sizes and tickets), test_nvn_host_tables, test_recording_log_handoff and test_switch_table pass. nvn_native.c compiles syntax-only with the builder's flags (0 errors).
  • WSL Ubuntu 24.04 (gcc 13.3): run_all --changed 1780fbe0 passed 30, failed 10. The 10 are the same 10 that fail on main there. test_nvn_recording_copies and test_hos_ab, skipped by run_all there for want of clang, pass when run with --cc gcc; they needed two fixture fixes for gcc, which are in 2763ba17.
  • Not run: a Linux game build, the Steam Deck, and this PR together with #1780 or #1811.
Thanks, both points were right. New head: 2763ba17 (66fb7c1c is the fix and 2763ba17 makes the test build with gcc). **1. The sweep's ticket was read too early.** This was real, and main has it too. main read `rx_nvn_pushed() + held_count()` under the lock but before the slice read its marks, so the window was smaller but there. In `host/nvn_native.c` the ticket is now `retire_ticket()`, read where the copy is actually retired: - `sweep_buckets` reads every mark of its batch first, unlinks the copies whose marks were overwritten, and only then reads the ticket and lets them go. - `release_copies` reads the ticket inside its hold of `copy_lock`, after the AddControlMemory call that retires the copies. - The held count is read before pushed, with fences around the two reads. `held_flush` counts its submits up in pushed before it clears the held count, so a flush between the two reads counts those submits once or twice, never zero times. The other order (and C's unspecified order of the old `a() + b()`) could miss them. Both ways (`HOS_NVN_REC_OLD` unset and `=1`) get the fix. Test: `tests/test_nvn_recording_copies.py`, `tickets()`. The stubs `rx_nvn_pushed` and `held_count` have a pause point, which makes two cases deterministic: - **(a)** The sweep is paused after reading its ticket. Meanwhile a producer submits the copy at N + 1 and then overwrites its mark. - **(b)** A held submit names the copy, the game overwrites its mark, and the flush runs between the ticket's two reads. In both cases the copy must still be on the dead list, with its bytes counted, when the replay is at N. It must be freed once the replay has passed its submit. Before and after: - Against b8d2204b's `nvn_native.c`, (a) fails both ways: the copy is freed with the replay at N. (I ran the new fixture with only the take_due/node helpers adapted to that head's names.) - Two broken variants of the new code are caught: `ticket-early` (b8d2204b's expression before the marks) by (a), and `pushed-first` by (b). **2. The prefix grew from 24 to 48 bytes even with the rollback.** Fixed at the root: `copy_prefix` is main's 24 bytes again, and the bucket nodes are main's `rec_node`, both ways. So a copy's block is byte for byte main's, and `HOS_NVN_REC_OLD=1` is no longer partial. Test: `sizes()` records a 65,504-byte recording and requires a 65,528-byte copy in the 64 KiB class, both ways. It fails on b8d2204b both ways; the `prefix-48` broken variant is caught. **#1780.** I read its diff at 620f3067. Its `rec_begin` / `rec_end` hand a half-full segment over as the handle, which is the same mechanism and the same rule as this PR's `end_copy`. Only one of them can be on. #1780's should win: - it came first; - it is that one change behind its own switch (`HOS_NVN_REC_HANDOFF`); - it is measured at its own head (+4.4 % standing in the Market on main a433db32); - this PR's hand-over never showed a gain. So `end_copy` and the `REC_HEAD` room are gone from this PR. What is left is independent of it: - segment size hints by guest address; - dead copies and nodes freed once `copy_lock` is let go; - the sweep in 128-bucket batches outside EndRecording's hold; - the handle prefetch; - the ticket fix. Either PR can merge first. The only overlap left is text next to BeginRecording, EndRecording and `flatten`, with no shared semantics: #1780's `rec_end` writes main's 24-byte prefix, and that is the prefix here again. **#1811.** This PR no longer changes what is submitted or when. It only moves the ticket read later, so it is reconciled with #1811 by construction. They have not been tested together. **Does it help?** No. Measured at exact heads: base main 1780fbe0 (this branch's base) and the PR at 2763ba17, with on and off (`HOS_NVN_REC_OLD=1`) from the same build. Setup: - Windows 11, RTX 4070 SUPER (617.42), Ryzen 9 9950X3D with SMT off. - Market_Child, standing still after a teleport from `kokiri-start`, 160 s, headless at 1920x1080, `HOS_FPS_MAX=1000`. - Frames from 300 after arrival to the end. - Runs in the order M ON OFF OFF ON M at each affinity. | | main 1780fbe0 | PR on | PR off | |---|---|---|---| | 4 cores (0xF00): fps, the two runs | 75.9, 77.0 | 75.8, 76.8 | 76.7, 77.6 | | 4 cores: p99 / p99.9 ms (means) | 16.95 / 20.16 | 17.25 / 20.35 | 17.05 / 21.11 | | 16 cores (0xFFFF): fps | 90.6, 89.5 | 89.7, 90.4 | 89.8, 89.8 | | 16 cores: p99 / p99.9 ms | 13.42 / 15.36 | 13.59 / 16.03 | 13.54 / 15.37 | | private bytes at the end (MB) | 20,832-20,930 | 20,699-21,092 | 20,828-21,030 | | live copies (MB, last 50k line) | 22.9-24.8 | 22.6-24.1 | 22.8-23.7 | Every difference is inside the spread of the same arm's two runs, frame tails included. No `not a live recording`, no FATAL and no frame of 50 ms or more. The game threads' CPU over the last 2 minutes (`HOS_THREAD_TIMES=5`, threads over 5 %) is the same within about 2 % in every arm, so I can't show less contention either. The copy lock's wait was not measured directly. What this PR can claim now is the ticket fix, a race main has too. Otherwise it is bookkeeping with no measured effect. If you'd rather not carry that, I can split the ticket fix into its own small PR on main and close this one. Checks at 2763ba17: - **Windows (clang):** `test_nvn_recording_copies` (both ways, 7 broken variants caught), `test_hos_ab` (including the flips run, which now also runs `sizes` and `tickets`), `test_nvn_host_tables`, `test_recording_log_handoff` and `test_switch_table` pass. `nvn_native.c` compiles syntax-only with the builder's flags (0 errors). - **WSL Ubuntu 24.04 (gcc 13.3):** `run_all --changed 1780fbe0` passed 30, failed 10. The 10 are the same 10 that fail on main there. `test_nvn_recording_copies` and `test_hos_ab`, skipped by run_all there for want of clang, pass when run with `--cc gcc`; they needed two fixture fixes for gcc, which are in 2763ba17. - **Not run:** a Linux game build, the Steam Deck, and this PR together with #1780 or #1811.
Author
Member

@Beanstalk steamdeck: Castle Town's market (child), standing for 3 minutes after a teleport from kokiri-start, with HOS_AB=HOS_NVN_REC_OLD=1,3,60 RX_VK_FRAME_TRACE=1, then scripts/ab_summary.py. Expecting side 1 (the old bookkeeping) no faster than side 0, and no not a live recording in the log. Also linux, any GPU: the same, to check the changed host code runs there.

(Earlier runs on #1846 and #1847 today ended in error before building: the farm's checkout of main failed git rev-parse --verify HEAD^{commit} in packs.py's cmd_base, so nothing was measured there.)

@Beanstalk steamdeck: Castle Town's market (child), standing for 3 minutes after a teleport from kokiri-start, with `HOS_AB=HOS_NVN_REC_OLD=1,3,60 RX_VK_FRAME_TRACE=1`, then scripts/ab_summary.py. Expecting side 1 (the old bookkeeping) no faster than side 0, and no `not a live recording` in the log. Also linux, any GPU: the same, to check the changed host code runs there. (Earlier runs on #1846 and #1847 today ended in `error` before building: the farm's checkout of main failed `git rev-parse --verify HEAD^{commit}` in packs.py's cmd_base, so nothing was measured there.)
Member
Beanstalk test farm · an earlier run: commit 2763ba1 (the newer results are in a comment below)

Commit 2763ba1 · tier reviewed · approved by GummiNaomi · dashboard

What will be tested · AI plan (gpt-6.1-terra)

On Steam Deck and on a Linux PC, the plan loads kokiri-start, teleports to the child Market, and stands for three minutes on both main and the PR. It enables the requested in-game bookkeeping alternation and compares frame times, memory, and a Market screenshot; crashes, a “not a live recording” log message, or the specified regressions fail. The farm cannot enable the requested frame trace or run ab_summary.py, so this plan cannot judge whether side 1 is faster than side 0. Each target takes about 16 minutes of game runs, excluding builds.

  • Where: steamdeck (1-2 reports), linux (1-2 reports).
  • child-market: from the repository's save kokiri-start (switches HOS_AB=HOS_NVN_REC_OLD=1,3,60), then teleport to Market, take the picture market to compare with main, measure stand for 3 min (after 0 s warm-up); 1 run on each side.
  • Measured: crashes, frame times, stutters and hitches, memory and CPU time, the game's log.
  • The PR fails if: it crashes; or a picture differs from main by more than 5%; or peak memory is more than 10% above main; or frame time (p99) is more than 15% above main; or forbidden log lines is above 0.
  • Time: about 16 min of game runs per tester (2 game starts), plus the two builds.

Started at 13:13 UTC.

Estimate: done in about 9 h 15 min, from the queue and the testers online now; some jobs can't start yet.

Target Reports Crash Frame p99 (ms) vs main VRAM peak (MB) vs main Result
steamdeck 0/1 — — — queued
linux · 1: linux+other unknown, unknown 1/1 1 none — — running

Measurements · linux

Verdict: running on linux (1/1 report).

Hardware: 1: linux+other unknown, unknown AMD Ryzen 7 5700X3D 8-Core Processor, 128 GB RAM
Scene: child-market, from the repository's save kokiri-start (HOS_AB=HOS_NVN_REC_OLD=1,3,60); each cell's settings and switches as the table names them
Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); child-market: 1 game start a side, stand 180 s after 0 s warm-up; each number the median of the runs, then of 1 report
How to reproduce: the farm's plan above (@Beanstalk on this PR runs it again)

Nothing was measured: no metric came back.

Flags and settings

None: the plan varied no setting, switch or build option.

Markdown for the PR description
## Measurements

**Verdict:** running on linux (1/1 report).

Hardware: 1: linux+other `unknown, unknown` `AMD Ryzen 7 5700X3D 8-Core Processor, 128 GB RAM`  
Scene: child-market, from the repository's save kokiri-start (HOS_AB=HOS_NVN_REC_OLD=1,3,60); each cell's settings and switches as the table names them  
Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); child-market: 1 game start a side, stand 180 s after 0 s warm-up; each number the median of the runs, then of 1 report  
How to reproduce: the farm's plan above (`@Beanstalk` on this PR runs it again)

Nothing was measured: no metric came back.

### Flags and settings

None: the plan varied no setting, switch or build option.
<!-- beanstalk:previous --> <details><summary>Beanstalk test farm · an earlier run: commit <code>2763ba1</code> (the newer results are in a comment below)</summary> Commit `2763ba1` · tier **reviewed** · approved by GummiNaomi · [dashboard](https://beanstalk.magicbean.dev/prs/1812) **What will be tested** · AI plan (`gpt-6.1-terra`) On Steam Deck and on a Linux PC, the plan loads kokiri-start, teleports to the child Market, and stands for three minutes on both main and the PR. It enables the requested in-game bookkeeping alternation and compares frame times, memory, and a Market screenshot; crashes, a “not a live recording” log message, or the specified regressions fail. The farm cannot enable the requested frame trace or run ab_summary.py, so this plan cannot judge whether side 1 is faster than side 0. Each target takes about 16 minutes of game runs, excluding builds. - **Where:** steamdeck (1-2 reports), linux (1-2 reports). - **child-market:** from the repository's save `kokiri-start` (switches `HOS_AB=HOS_NVN_REC_OLD=1,3,60`), then teleport to Market, take the picture market to compare with main, measure stand for 3 min (after 0 s warm-up); 1 run on each side. - **Measured:** crashes, frame times, stutters and hitches, memory and CPU time, the game's log. - **The PR fails if:** it crashes; or a picture differs from main by more than 5%; or peak memory is more than 10% above main; or frame time (p99) is more than 15% above main; or forbidden log lines is above 0. - **Time:** about 16 min of game runs per tester (2 game starts), plus the two builds. Started at 13:13 UTC. **Estimate:** done in about 9 h 15 min, from the queue and the testers online now; some jobs can't start yet. | Target | Reports | Crash | Frame p99 (ms) vs main | VRAM peak (MB) vs main | Result | | --- | --- | --- | --- | --- | --- | | steamdeck | 0/1 | — | — | — | queued | | linux · 1: linux+other `unknown, unknown` | 1/1 [1](https://beanstalk.magicbean.dev/reports/rp_ab663c5478724fab) | none | — | — | running | #### Measurements · linux **Verdict:** running on linux (1/1 report). Hardware: 1: linux+other `unknown, unknown` `AMD Ryzen 7 5700X3D 8-Core Processor, 128 GB RAM` Scene: child-market, from the repository's save kokiri-start (HOS_AB=HOS_NVN_REC_OLD=1,3,60); each cell's settings and switches as the table names them Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); child-market: 1 game start a side, stand 180 s after 0 s warm-up; each number the median of the runs, then of 1 report How to reproduce: the farm's plan above (`@Beanstalk` on this PR runs it again) Nothing was measured: no metric came back. ### Flags and settings None: the plan varied no setting, switch or build option. <details><summary>Markdown for the PR description</summary> ```markdown ## Measurements **Verdict:** running on linux (1/1 report). Hardware: 1: linux+other `unknown, unknown` `AMD Ryzen 7 5700X3D 8-Core Processor, 128 GB RAM` Scene: child-market, from the repository's save kokiri-start (HOS_AB=HOS_NVN_REC_OLD=1,3,60); each cell's settings and switches as the table names them Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); child-market: 1 game start a side, stand 180 s after 0 s warm-up; each number the median of the runs, then of 1 report How to reproduce: the farm's plan above (`@Beanstalk` on this PR runs it again) Nothing was measured: no metric came back. ### Flags and settings None: the plan varied no setting, switch or build option. ``` </details> </details>
GummiNaomi force-pushed perf/nvn-recording-copies from 2763ba174b
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 7s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 11s
CI / Workflow lint (actionlint) (pull_request) Successful in 11s
Third-party parts / As their notes say (pull_request) Successful in 12s
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Failing after 5s
beanstalk/approval approved by GummiNaomi (reviewed)
beanstalk/steamdeck 0/1 pass, 0 running, 2 queued
beanstalk/linux 0/1 pass, 1 running, 0 queued
CI / Website build and checks (pull_request) Has been cancelled
to 451591028d
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 13s
PR description / Description follows the template (pull_request_target) Failing after 18s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 19s
CI / Workflow lint (actionlint) (pull_request) Successful in 22s
Third-party parts / As their notes say (pull_request) Successful in 23s
beanstalk/approval not approved yet
CI / Website build and checks (pull_request) Failing after 2m4s
2026-11-20 14:08:17 +00:00
Compare
Member

Beanstalk test farm

Commit 4515910 · approved by nobody yet · dashboard

A member of BigBeans can review this commit and comment @Beanstalk to test it.

<!-- beanstalk:sticky --> ### Beanstalk test farm Commit `4515910` · approved by nobody yet · [dashboard](https://beanstalk.magicbean.dev/prs/1812) A member of `BigBeans` can review this commit and comment `@Beanstalk` to test it.
Author
Member

Closing: no change at 4 or 16 cores against main, in frame rate, frame tails or memory. The one part with value on its own is the fix for the sweep's ticket read (the ticket read at retirement, not at the sweep); I can send that as a small PR of its own if you want it.

Closing: no change at 4 or 16 cores against main, in frame rate, frame tails or memory. The one part with value on its own is the fix for the sweep's ticket read (the ticket read at retirement, not at the sweep); I can send that as a small PR of its own if you want it.
GummiNaomi closed this pull request 2026-11-20 21:01:59 +00:00
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 13s
PR description / Description follows the template (pull_request_target) Failing after 18s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 19s
CI / Workflow lint (actionlint) (pull_request) Successful in 22s
Third-party parts / As their notes say (pull_request) Successful in 23s
beanstalk/approval not approved yet
CI / Website build and checks (pull_request) Failing after 2m4s

Pull request closed

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!1812
No description provided.