WIP: perf(host): a finished command recording is handed over instead of copied (HOS_NVN_REC_HANDOFF=0 to copy) #1780
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
5 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!1780
Loading…
Reference in a new issue
No description provided.
Delete branch "snaildev99/Longshot:perf/rec-handoff"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Every time the game finishes recording a batch of drawing commands, Longshot copies that batch once more on the game's own thread before the renderer gets it: about 750,000 recordings in a 75-second run of Castle Town's Market.
docs/cpu-profile.mdlists this copy as candidate 4, at 2.6 % of a core with 1.3 % on the serial threads. This PR hands a large finished recording over as it is and gives the command buffer a fresh segment instead, so that copy is no longer made. It is on by default;HOS_NVN_REC_HANDOFF=0copies every recording as before.The goal is less work on the game's threads for the same result. Frame rate is the check that nothing got slower, and where the processor sets the frame it rises: the Market ran 4.4 % faster standing still and 4.1 % faster turning the camera on main
a433db32(three interleaved runs a side), and +4.3 % / +2.2 % as the mean of eight on/off pairs in a 48-run matrix, with no memory growth.How:
rec_beginstarts a recording after room for a copy's prefix;rec_endturns a recording that fills at least half of its segment into the handle (the prefix written in its room) and gives the command buffer a fresh segment; anything smaller goes throughflattenas before. A handed-over block is laid out and freed exactly as a copy (free_dead_copies,release_copies, the sweep). Why half: copies live until their control memory is added again (about 53,000 live in the Market), and a segment is at least 64 KB, so handing over small recordings would multiply memory; at half full the block is at most twice the recording, the bound the pool's power-of-two classes already give a copy. Since0f94b30cthenvn:line written every 50,000 recordings also says how many of those were handed off (the rest copied) and how many blocks the recording pool took from the heap since the last line, so a log shows how often the hand-off acts on a PC and whether its fresh segments come from the pool.Read first:
host/nvn_native.c(rec_handoff_on, read withenv_on_or(..., 1);rec_begin,rec_end, and their calls in BeginRecording and EndRecording);tests/test_nvn_rec_handoff.py; the row ingpu/vk/switches.def.See #1504 (the same function on Linux, from the lock side); #1034 touches its write marks. Neither is this change.
Testing
Tested: Windows 11, RTX 3090 (NVIDIA 610.88), Ryzen 9 5900X. In the game: this change at its pre-rebase head in a test tree on main
a433db32(test/perf-prs@ be5623e0 on my fork, built from scratch twice, 0 failed): 15 hands-free Market runs, 6 with the switch on; in a v3.0.0 test tree, 24 Market runs with it on (15 s standing, 40 s turning each); before that two dozen hands-free runs in the Market and Hyrule Field with the first version on main544229a2. Nonot a live recording, noFATALand no frame of 50 ms or more in any log. The rebase onto main068fb8eb(#1802) changed no code: onlydocs/development.md, which #1802 removed, lost the switch's row (its row ingpu/vk/switches.defis the reference now). The default went on in620f3067(env_on_or, the row akillswitch, the test run unset and=0): the code paths are the ones measured, only which is the default changed. Game-free at this head (620f3067):tests/test_nvn_rec_handoff.py(compiles the real pool,cmd_reserve_rec,flatten,rec_begin,rec_end; 3,000 recordings of 16 bytes to 1.5 MB in four command buffers, 64 handles kept, on and=0: every handle holds its bytes after later recordings and segment growth; on: 106 handed over, 2,894 copied; every block back in the pool; an end without a begin is copied as before; three controls fail it) andtests/test_switch_table.pyandtests/test_env_on.pypass.tests/run_all.pyon Windows at this head: 708 passed, 47 failed, 116 skipped; main068fb8ebon this PC: 704 passed, 50 failed, 116 skipped. No failure that main does not have: main's, apart from timing tests that failed in one run only and pass when run alone (test_invalidate_vcore,test_compile_stops_on_exception,test_longshot_ctl,test_mesh_args_cleanup);test_vbytestimes out at 600 s in both. Main's failures on this PC:test_appimage_player_build,test_auto_handheld,test_bug_report_defaults,test_capture_read_once,test_crash_dialog,test_crt_options,test_damage_debug_menu,test_dev_ab,test_dev_build,test_dev_migrate,test_dev_packs,test_display_startup_failure,test_dlss_feature_size,test_failed_compile_keeps_objects,test_frame_overlap,test_frame_wait_bounds,test_game_menu_mouse_buttons,test_guest_imported,test_high_fps_fixes,test_host_guest_writes,test_hud_layout_row,test_job_queue,test_libc_hooks,test_lift_cache,test_linux_preflight,test_linux_pressure,test_make_game_ngx,test_mise_build,test_missing_nup,test_mods_list,test_ngx_sdk,test_pads_after_menu,test_pending_guest_import,test_pipeline_play_cache,test_portable_builder_home,test_portable_builder_startup,test_prepare_cache_save,test_present_thread,test_profiling_mode,test_psychov35_fsr3_fg,test_readback_timeout_source,test_sdiv_overflow,test_seed_reader,test_slow_frames,test_song_note_cue,test_upscaler_rows,test_vcore_escape,test_walk_key. A Steam Deck OLED run by dukenheimer at620f3067(comment below; 1280x800, GPU-bound at ~21 fps): standing in the Market, off against on, two pairs: 21.65 to 21.25 fps (-1.8 %), both on runs below both off runs, 1 % low 16.0 to 14.65 fps; not yet explained (see Still to test).0f94b30cchanges only the log line's counters:tests/test_nvn_rec_handoff.pypasses at it (the counters match its own counts, on and =0), andhost/nvn_native.ccompiles for Windows with the warnings main has.Still to test:
not a live recordingin the log (@Beanstalk linux).HOS_NVN_REC_HANDOFF=0against unset, at0f94b30c, with thenvn:lines' hand-off and heap-block counts from both arms beside the frame times, expecting no frame rate lost on the switch (by hand).RX_VK_ASYNC=0), expecting no fault and nonot a live recording(by hand).Measurements
Verdict: less work on the game's threads: large finished recordings are handed over, not copied. Frame rate is the check that nothing got slower, and where the processor sets the frame it rises: the Market +4.4 % standing and +4.1 % turning on main
a433db32; no change in memory. Where the renderer sets the frame (Hyrule Field by day) about +1 %.Baseline: one executable on both sides, the test tree
test/perf-prs@ be5623e0 on my fork (maina433db32with this PR and its siblings #1781 and #1782 merged, the default hot list,A64_VECFP=0so the lifted code is main's). Before is every switch unset, which then ran main's code path (the switch was opt-in when measured; with this PR's default the same two sides areHOS_NVN_REC_HANDOFF=0and unset); After sets only this one. Main has since moved four commits to068fb8eb(#1802 docs, tools and the PR template; #1774 and #1807 the Insert menu's rows; #1792 dev packs): outside comments, docs and the dev tools they change the Insert menu's code (#1774, #1807) and the version string and some log texts (#1802): nothing inhost/nvn_native.c, and nothing the Market runs each frame but the FPS counter's overlay, which runs alike on both sides. So the numbers hold.Setup: Windows 11 (build 22631), GeForce RTX 3090 (NVIDIA 610.88), Ryzen 9 5900X (12 cores), 128 GB. Child Link at the Market's save point by day; 3840x2160 full screen, frame rate cap Uncapped, no mods; the GPU wait 0.0 to 0.1 ms in every run (the processor sets the frame). Hands-free through
scripts/longshot_ctl.py: the save loads, 10 s to settle, 15 s standing (the FPS counter's value once a second), then 40 s with the right stick held to one side. Three runs a side, interleaved, the median.HOS_NVN_REC_HANDOFF=1: test/perf-prs @ be5623e0With its two siblings on as well, the same runs: 76.0 standing (+10.5 %) and 68.1 turning (+8.1 %). No frame of 50 ms or more, no
FATALand nonot a live recordingin any of the 15 logs.The 48-run matrix
The change was measured beside every combination of #1781, #1782 and main's
RX_VK_CAPTURE_NT, in one test treetest/perf-matrix@ 2c30c326 on my fork (v3.0.009cbdd97with the three changes, every lifted file at -O2 so that the hot list is not a variable, built withA64_VECFP=0and on). Sixteen variants, three interleaved runs each, 48 runs in 74 minutes with nobody at the PC. Before and After are the same executable; only this switch differs.RX_VK_CAPTURE_NT=1HOS_OBJ_CACHE=16384RX_VK_CAPTURE_NT=1HOS_OBJ_CACHE=16384Standing it gained in every pair (+2.3 to +3.9 fps). Peak working set over the eight pairs: 9,944 to 10,030 MB either way. The run file is
docs/tested/2026-11-19-rec-handoff-snaildev99-matrix-h.md.Offline (not a frame rate):
tests/test_nvn_rec_handoff.py --bench, a recording written in records of 32 to 256 bytes plus its end, best of 7: 256 KB 72 to 24 microseconds, 1 MB 381 to 98, 2 MB 288 to 196.The switch
HOS_NVN_REC_HANDOFF(new, run time, akillswitch): on by default, as the measurements chose (+4.4 % standing, +4.1 % turning; a gain in every standing pair of the matrix; no memory growth).HOS_NVN_REC_HANDOFF=0copies every recording, main's path, byte for byte.Risks
What could break: a handle read after its block was reused would draw garbage or lose the device; a handed-over block is freed by the same rule as a copy (only after the replay passed the submits made before its release). Memory: a handed-over block is at most twice its recording, as a copy's pool block is; the live copies' total did not grow in the runs (18.7 to 20.4 MB with and without). The fresh segment is cold memory, so the next recording's first writes pay the cache misses the copy's writes paid before; the frame rate above includes that.
Turning it off:
HOS_NVN_REC_HANDOFF=0(in the environment orlongshot_env.txt): every recording is copied, as on main.After updating: the hand-off is on; saves,
longshot_options.iniand the caches do not change.Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named).main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
gpu/vk/switches.def.tests/that reads changed source is updated, not weakened. (tests/test_nvn_rec_handoff.py, new;tests/test_switch_table.pyreads the new row.)620f3067built by the Test Farm's Linux and AMD testers and on a Steam Deck, and run in the Market;0f94b30cnot yet built there.)Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.🤖 Generated with Claude Code
Tested in game: Windows 11, RTX 3090 (NVIDIA 610.88), Ryzen 9 5900X: 24 hands-free runs in the child Market with HOS_NVN_REC_HANDOFF=1 (15 s standing, then 40 s turning the camera), in a test build of v3.0.0 with this change (test/perf-matrix @ 2c30c326 on my fork). No "not a live recording", no FATAL and no frame of 50 ms or more in any log; +2.3 to +3.9 fps standing in all eight on/off pairs. Not built or played at this head on current main yet: that is why this is WIP.
Possibly related, for context:
Built and played at this head. The test tree is
test/perf-prs@ be5623e0 on my fork: maina433db32with #1780, #1781 and #1782 merged, the default hot list, built from scratch twice (A64_VECFP=0, where the lifted code is main's, and the float paths on). Windows 11, RTX 3090 (NVIDIA 610.88), Ryzen 9 5900X, 3840x2160 uncapped, the child Market: 15 s standing, then 40 s turning the camera; five variants, three interleaved runs each, nobody at the PC, medians.HOS_NVN_REC_HANDOFF=1(#1780)HOS_OBJ_CACHE=16384(#1781)No frame of 50 ms or more, no
FATALand nonot a live recordingin any of the 15 logs; the object cache missed 0.69 % of 22 million lookups.Build cost of the float paths on a default build (both from scratch, 23 jobs): the lifted files' compiler time 7,374 s to 7,646 s (+3.7 %), the compile's wall time 458 s to 422 s (the slowest hot piece sets it, and it is not slower), lifted objects 679 to 687 MB.
The description has these numbers; the full 16-variant matrix on v3.0.0 is still its first table.
@Beanstalk linux: build this branch and play a few minutes in the Market with HOS_NVN_REC_HANDOFF=1 set, expecting the picture as without it and no "not a live recording" in the log. This is the one box left before ready: the host code has only been built on Windows.
@snaildev99 only members of
BigBeanscan start the farm.One of them can approve this request by reacting 👍 to it or to this comment.This request was ford1f9f73, and the PR has changed since (b8e3bbb), so a 👍 no longer approves it. Comment@Beanstalkagain to ask for the new commit.d1f9f73926b8e3bbbe47Rebased onto main
068fb8eb(b8e3bbbe). #1802 removeddocs/development.md, which held this switch's row; its row ingpu/vk/switches.defis the reference now, so that edit is dropped and no code changed. The description now uses the new template, and says plainly what this PR is for: less work on the game's threads (large recordings handed over, not copied), with frame rate as the check that nothing got slower.Why the numbers still hold on
068fb8eb: they were measured on maina433db32, and the four commits since (#1802 docs, tools and the PR template; #1774 and #1807 the Insert menu's rows; #1792 dev packs): outside comments, docs and the dev tools they change the Insert menu's code (#1774, #1807) and the version string and some log texts (#1802): nothing inhost/nvn_native.c, and nothing the Market runs each frame but the FPS counter's overlay, which runs alike on both sides. So the numbers hold.The farm request is reworded below, to measure the game's CPU time at a frame cap besides the frame times. A ~4 % change is close to what two runs a side can resolve, and the point of the change is less CPU time for the same frames.
@Beanstalk linux, and amd: the Market for a few minutes, HOS_NVN_REC_HANDOFF=1 against unset. Measure the game's CPU seconds with the frame rate capped at 60 (on a PC that holds 60 there), and the frame times uncapped. Expect the same frame rate or better with less CPU time, the picture as without the switch, and no "not a live recording" in the log.
@snaildev99 only members of
BigBeanscan start the farm.One of them can approve this request by reacting 👍 to it or to this comment.This request was forb8e3bbb, and the PR has changed since (620f306), so a 👍 no longer approves it. Comment@Beanstalkagain to ask for the new commit.WIP: perf(host): a finished command recording is handed over instead of copied (HOS_NVN_REC_HANDOFF, opt-in)to WIP: perf(host): a finished command recording is handed over instead of copied (HOS_NVN_REC_HANDOFF=0 to copy)The hand-off is now on by default (
620f3067): docs/dev/standards.md says a switch ships at the value its measurements chose, and never off just because it is new or unmeasured, and the measurements here choose on (the Market +4.4 % standing and +4.1 % turning on maina433db32, a gain in every standing pair of the matrix, no memory growth).HOS_NVN_REC_HANDOFF=0copies every recording, main's path, byte for byte. The switch is read withenv_on_or(..., 1), its row is now akillswitch, andtests/test_nvn_rec_handoff.pyruns it unset (on) and=0(off). Only the default changed: both code paths are the ones measured. The Linux and AMD / Intel runs below are now main against this PR.@Beanstalk linux, and amd: main against this PR in the Market for a few minutes (the hand-off is on by default now). Measure the game's CPU seconds with the frame rate capped at 60 (on a PC that holds 60 there), and the frame times uncapped. Expect the same frame rate or better with less CPU time, the picture as on main, and no "not a live recording" in the log.
@snaildev99 only members of
BigBeanscan start the farm. One of them can approve this request by reacting 👍 to it or to this comment.@Beanstalk
Beanstalk test farm · an earlier run: commit
620f306(the newer results are in a comment below)Commit
620f306· tier reviewed · approved by HumanBean · dashboardWhat will be tested · AI plan (
gpt-6.1-terra)On Linux and AMD PCs, the plan compares main with the PR in the child Market at capped and uncapped frame rates. Alternating runs take about 22 minutes per target and measure CPU time, memory, frame performance and pictures before and after a camera turn. Crashes, recording errors, substantial CPU or frame-time regressions, or picture differences fail the plan; CPU savings are measured but not required.
0or6.kokiri-start, then teleport to Market, measure standing for 30 s (after 10 s warm-up), take the picture market-standing to compare with main, move the stick, measure after-turn for 30 s (after 5 s warm-up), take the picture market-after-turn to compare with main; 2 runs on each side for each of 2 cells (1 game start a run).Done (started 08:12 UTC). Comment
@Beanstalkto run it again.frame_rate_cap=0frame_rate_cap=0frame_rate_cap=6frame_rate_cap=6Tested #1780 at
620f3067on main068fb8ebplus a local stand-in for #1815 in both arms. Steam Deck OLED, 1280×800, fullscreen Game Mode, HDR on, GPU held at peak clocks as main does on Deck.Standing in the Market, I alternated
HOS_NVN_REC_HANDOFF=0and1; #1814 and #1810 stayed off. Two pairs, 60 s per run. Medians, off → on:I didn't see a standing gain. Two pairs are a first check, not enough to call a regression. There's no hand-off counter: I know the switch was on, not how often a hand-off happened.
Moving, the Field walk was main → all three on (2 pairs): 21.85 → 22.7 fps (+3.9%), 1% low 12.45 → 14.7 fps, p99 80 → 68 ms, and frames over 50 ms 16.3% → 8.55%. There was no moving run with only #1780 on.
Beanstalk test farm
Commit
0f94b30· approved by nobody yet · dashboardA member of
BigBeanscan review this commit and comment@Beanstalkto test it.Thanks for running this, and for the careful write-up. At ~21 fps the Deck is GPU-bound, so the hand-off (less CPU work when a recording ends) isn't expected to raise the frame rate there, but it must not cost frames, and your standing pairs lean that way. One way it could cost more on Linux than on the Windows PC it was measured on: a handed-off recording keeps its whole segment, and the command buffer takes a fresh one, from the heap whenever the pool is empty, which on Linux can mean new pages faulted in.
0f94b30cadds the counter you asked for to thenvn:line (written every 50,000 recordings): how many of those were handed off, the rest copied, and how many blocks the recording pool took from the heap since the last line. If you have time, the same standing pairs at0f94b30cwith those lines from both arms would show whether the hand-off acts as often as on Windows and whether it pays in fresh heap blocks.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.