WIP: perf(nvn): a recorded command's room is checked inline and its header written once #2050
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
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2050
Loadingโฆ
Reference in a new issue
No description provided.
Delete branch "siantm/Longshot:perf/nvn-record-inline"
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 NVN command the game records goes through
rec()orcmd_alloc(), thencmd_reserve_rec()(inhost/nvn_native.c): three calls a command.cmd_reserve_recwas one function holding both the test (does the recordfit in the segment) and the growth (a new segment from the pool, the old one's bytes copied over);
cmd_allocwrote aheader of op 0 that every caller then wrote over with its own (
rec, BeginRecording, EndRecording, the pushconstants, the uniform updates);
reczeroed its payload throughmemsetwith a length computed at the call.With this, the test is an inline function and the growth is
cmd_grow, out of line and cold, with the same body asbefore;
cmd_allocis inline and leaves the header to its caller;recis always inline, so for the constant payloadsizes of nearly every call the zeroing is a few stores. The result expected: less work for each recorded command on
the recording threads; the bytes recorded and the command memory counts are the same.
No switch: the same bytes either way, so a revert is enough.
From the local integration commit d1e33769 on
exp/x86-asm-sync(therecmd_growalso carriedHOS_NVN_SEG_PEAKand the hand-off's segment prefix, which are not part of this). Prior work: a forge search (cmd_alloc, cmd_grow) finds
no pull request on it; #1812 (GummiNaomi) changed only where a first segment starts (size hints) and was closed
unmerged by its author with no change at 4 or 16 cores. This one leaves the sizes as they are and changes only the
calls. Related: #1954 (open) writes the bind records field by field instead of through
rec(); this one makescmd_allocandrec()inline for every record, the two merge without conflict, and #1954'sbind_handleswrites itsown header after
cmd_alloc, as every caller must here.Read first:
cmd_grow,cmd_reserve_rec,cmd_allocandrecinhost/nvn_native.c, thentests/test_nvn_record_inline.py.Testing
Tested: Windows 11, i7-9700, RTX 4060, the builder's llvm-mingw clang 23; head
6e07c3eaon main75317e1f. Build jobs of this PC's job queue, each runningtests/run_all.py --strict --exactwith every check in a hidden console: batchAsmCut4-b1(logt-AsmCut4-nvn-record-inline.log):tests/test_nvn_record_inline.py,tests/test_host_alloc_wait.pyand every check--changed 75317e1fpicks for the files this changes: 23 checks, 20 passed, 3 failed, 0 skipped;tests/test_nvn_record_inline.pypasses,tests/test_host_alloc_wait.pypasses; batchAsmCut3-b1b(logt-AsmCut3b-nvn-record-inline.log, at the earlier cut163b8dd0):tests/test_host_alloc_wait.pyand every check--changed 75317e1fpicks for the files this changes: 23 checks, 19 passed, 4 failed, 0 skipped;tests/test_host_alloc_wait.pypasses (there the own check,tests/test_nvn_record_inline.py, failed to build its fixture under clang's -Werror (a variable of the slot table the cut leaves unused, in the test), fixed in this head and passing in the run above). The other failures fail on the base too, run from a base worktree (batchAsmCut3-b1, logt-AsmCut3-base-main.log):tests/test_dev_packs.py(fails on main @75317e1ftoo),tests/test_host_guest_writes.py(fails on main @75317e1ftoo),tests/test_renderer_new_handler.py(fails on main @75317e1ftoo).It has NOT run in the game on this PC yet.
Still to test:
75317e1fagainst this PR, eachwarmed a minute, then at least three interleaved three-minute runs of each (AB AB AB), expecting the same picture, no
FATAL, and fps and frame times of this PR at least main's; a difference beyond the runs' spread is a gain or a loss,
one within it is no difference measured (by hand)
warmed and interleaved, expecting the same picture and no FATAL (@Beanstalk linux+nvidia, linux+amd, windows+amd,
windows+intel, steamdeck: Kokiri Forest three minutes on main and on this PR, warmed and interleaved, frame times and
a screenshot)
python3 -I -B tests/test_nvn_record_inline.py --cc gcc, expecting PASS (by hand)Measurements
Verdict: not measured: no micro-benchmark of this port and no run in the game on this PC yet; the in-game
comparison is in Still to test. The branch's reason was its CPU profile (
docs/cpu-profile.mdonexp/x86-asm-sync,Hyrule Field, taken of the branch's code, not of this port), where
cmd_reserve_recshowed in its own instructions;no number of it is quoted here.
Risks
What could break: a record whose header or payload came out wrong would show as wrong or missing draws in any scene.
Every caller of
cmd_allocwrites its header right after it (the test checks each in the source), and the testrecords 40,000 records over eight command buffers and compares each segment with the bytes written, across its
growths. A revert is enough. Host code: the runtime is rebuilt; nothing changes for players' saves, options or caches.
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
tests/that reads changed source is updated, not weakened.Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.@Beanstalk This makes NVN command recording do less work for every recorded command on the recording threads (host/nvn_native.c), in every scene. No switch: a revert gives back main's code. It has not run in the game on these PCs yet. Please play Kokiri Forest and Hyrule Field, two minutes each, the PR against main on the same PC, with a picture in each compared with main's, on Linux with NVIDIA, Linux with AMD (RADV), Windows with Intel and the Steam Deck. The same picture as main, no crash and no FATAL line; frame time p99 equal to main's or better, within the run-to-run spread.
@siantm only members of
BigBeanscan start the farm. One of them can approve this request by reacting ๐ to it or to this comment.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.