WIP: perf(lift): the lifted code built with a play profile, every chunk (assets/profiles/longshot_game.profdata.xz) #2308
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
4 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2308
Loading…
Reference in a new issue
No description provided.
Delete branch "dyst/Longshot:perf/lifted-pgo"
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
Stacked on #2235 (RX_FP_NATIVE): the profile was recorded from its float headers, so merge #2235 first. This PR's own
commit is
38a23405; the diff againstmainshows #2235's three commits as well.The build can compile the hot pieces with a play profile (
RX_PGO, a checkout'swork/longshot_pieces.prof), but noneships (#1635: "no play profile of the pieces ships"), and the other lifted chunks never get one. This PR:
assets/profiles/longshot_game.profdata.xz(975 KB; 18.9 MB unpacked), recordedover six scenes (Market, Lake Hylia, Kakariko Village, Hyrule Field, Kokiri Forest, the Fire Temple), 30 s each;
nx2/make_game.pygame_profile_for, asvk_profile_fordoes the renderer's): the hot pieces at-O2as before, the other chunks at-O1with it too. On theMarket the chunks' share doubled the gain against the hot pieces alone (game loop -9% against -5%);
-DLONGSHOT_PROFILE_SHA1), as the hot pieces' already were (#660);RX_PGO=gencount every chunk, so one run records the whole profile.Switches (build time, rows in
docs/dev/reference/build.md):LONGSHOT_GAME_PROFILE=0builds without it;LONGSHOT_PGO_CHUNKS=0keepsRX_PGOto the hot pieces alone.RX_PGOset by hand or a checkout'swork/longshot_pieces.profstill goes first;RX_FP_NATIVE=0builds without it (the shapes differ).What the profile holds: lifted function names (
f_<guest address>,s_<address>_<n>), a hash of each one's shape and itsbranch counts; no game code or data, like
hot_funcs.txtbeside it. How it was recorded is inassets/profiles/README.md.It ages rather than breaks: a function whose shape changes (a new translator, a patch) compiles as if there were no
profile.
Read first:
game_profile_forinnx2/make_game.py, theRX_PGOblock innx2/build.py,assets/profiles/README.md.Related: #1976 (the build saying how well the profile fits) would show this profile's fit; #1986 (a profile for the
runtime's own files) is separate.
Testing
Tested: Windows 11, Ryzen 9 3900X, RTX 3080 (NVIDIA 621.14), 3440x1440 window at 67%, V-Sync off, uncapped. The head
38a23405packed over the v3.1.1 base with no switch set (its log: "the lifted code's play profile: ...longshot_game.shipped.profdata"), A/B against #2235 at
388fa3cbin Hyrule Field and the Market, 2 runs a side each:every run reached its scene and played its 60 s, nothing wrong seen.
tests/test_game_pgo.pypasses ("game pgo: pass")and fails on #2235's branch (no
game_profile_for).Still to test:
@Beanstalkthe Market and Hyrule Field against #2235, expecting a gain of the same order.
@Beanstalkthe same, expecting more of the game loop's cut to show as fps.@Beanstalk.mise run test, by hand.Measurements
Verdict: faster: Hyrule Field +8.8% fps, the Market +2.4%, every run of this PR above every run of #2235 in both; the
game loop 9% and 5% shorter.
Setup: Windows 11, Ryzen 9 3900X, RTX 3080 (NVIDIA 621.14), 3440x1440 window, render resolution 67%, V-Sync off,
uncapped (
HOS_FPS_MAX=1000),dev.py ab's runs (60 s after the warm-up, A1 B1 A2 B2).game_msis the frame trace'sgame loop.
388fa3cb38a23405game_ms(median)game_ms(median)longshot.exeEarlier runs of the same change (local measurement branches, the profile's first recordings): the Market-only profile
gave Lake Hylia's game loop -18% (fps +1.5%: the render chain holds the frame there); a three-scene profile Hyrule Field
+7.6% and the Market +4.2% with Hyrule Field in none of its scenes; the six-scene profile measured the same as the
three-scene one. Building the whole game at
-O2on top added nothing (-1.0%, -0.6%) for 2.5x the compile time.Risks
(
assets/profiles/README.mdsays how); until then the gain shrinks.profile_readable), as with the renderer's.LONGSHOT_GAME_PROFILE=0(orLONGSHOT_PGO_CHUNKS=0for the hot pieces alone). A player notices the speed; thegame is built again once.
Checklist
Ready for review
main; the title is a Conventional Commit. Stacked on #2235 (WIP).mise run testpasses (any failure that also fails onmainis named). Not run yet;tests/test_game_pgo.pypasses.main, or Measurements says why there is nothing to measure. (Against #2235, which it builds on.)third_party/untouched; nothing GPL-incompatible.When it applies
gpu/vk/switches.def.Build switches (
LONGSHOT_GAME_PROFILE,LONGSHOT_PGO_CHUNKS): rows indocs/dev/reference/build.md, on by default.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, Ryzen 9 3900X, RTX 3080 (NVIDIA 621.14), 3440x1440 window at 67%, V-Sync off, uncapped. The head
38a23405packed over the v3.1.1 base with no switch set (the log names the committed profile), A/B against #2235 at388fa3cb, 2 runs a side: Hyrule Field 76.8/77.2 -> 84.4/83.1 fps, the Market 59.2/58.1 -> 60.6/59.5 fps. Every run reached its scene and played through; nothing wrong seen.Possibly related, for context:
🤖 A suggestion for the play profile's scenes: Lost Woods.
We surveyed every Debug-tab destination for CPU load on a 5700X3D + RX 9070 XT, at base
dd5ffe6a, with the camera turning and the frame rate uncapped. Lost Woods (child or adult) came out the heaviest: about 57-59 CPU ms a frame, against about 45 at Hyrule Field's usual spot. It is CPU-bound, with GPU time around 4 ms of a 12 ms frame.Most of that time is the job workers in the Havok cloth, a path the current profile scenes may barely exercise. We now run our standard test there (teleport 5 from a child save).
🤖 Generated with Claude Code
Steam Deck and Linux data for the "Still to test" list, from a player. These are local test builds, not the PR head packed by CI.
Build:
a2dc5385+ #2235 + this PR (head38a23405), built from source on Linux forRX_MARCH=znver2. Three variants come from the same tree:pgofpnLONGSHOT_GAME_PROFILE=0baseRX_FP_NATIVE=0a2dc5385The variants differ only in
bin/longshot,bin/longshot_vk.soand build-stamped files. The pipeline caches were shared between them.Linux question (does the AppImage-style clang read the profile?): yes. clang 23.1.5 from
tools.lockread the committed profile:llvm-profdata showreads it asFront-endinstrumentation with 18723 functions.profile_readable()probe returns rc 0.the lifted code's play profile: .../longshot_game.shipped.profdata.One caveat: the lifted chunks compile with
-Wno-everything(nx2/build.py), so clang's profile-mismatch warnings are suppressed and I could not measure the fit.Linux desktop, i7-8700K masked to 4C/8T (
taskset), RTX 3060 Ti, Market entrance, standing still, Deck-like render mode (RX_VK_ASYNC=0 RX_VK_RECORDER=off), 3 interleaved runs a side,pgovsfpn(x86-64-v3 builds):game_ms(median): 5.78 → 5.10 ms (-11.9 %). Everypgorun beat everyfpnrun (5.05-5.29 vs 5.76-5.91).pgoandfpnbeyond what two runs of the same build differ by.Steam Deck LCD (SteamOS 3.9.5, RADV), headless bench, 3 interleaved rounds of pgo / fpn / base, Market entrance, 90 s warm-up then a 60 s window, standing still:
fpnvsbase):game_ms14.92 → 12.53 (-2.4 ms, -16 %), run-to-run range [-2.85, -0.65].pgovsfpn):game_ms-0.07 ms [-3.3, -0.01]. Noise-sized on the Deck, unlike the -12 % on the desktop above. CPU time trends down (-6 ms/frame) but the range holds 0.HOS_HEADLESS) at an output resolution of 2560x1440 (see the correction below), and render_ms was ~30-34 ms, about twice what the Deck shows at its own 1280x800 in Game Mode. The frame was render-bound, so the game-loop savings could not reach it.Bench summary (per-run table + both A/B tables): deck-bench-745-pgo-fpn-base-summary.txt
Correction: the bench did not render at 1920x1080. That is only the size of its offscreen present image. With no screen, the game's output resolution falls back to 2560x1440 (
oe: output resolution 2560x1440 (none chosen: the game's)in every run's log), 3.6x the pixels of the Deck's own 1280x800. The bench now setsHOS_OUTPUT_RES=1280x800; the re-run follows.Assisted-by: Claude
Follow-up Steam Deck run, now on v3.2.0 and at the Deck's own 1280x800. Every run's log says
oe: output resolution 1280x800, set withHOS_OUTPUT_RES.Build: a local merge of v3.2.0 (
79d192c6) with this PR (38a23405, which includes #2235), built forRX_MARCH=znver2. Three variants come from the same tree:pgo: defaults.fpn:LONGSHOT_GAME_PROFILE=0.base:RX_FP_NATIVE=0, which behaves as stock v3.2.0.Run: Steam Deck LCD, headless, Market entrance, standing still, 90 s warm-up, 60 s window, 3 interleaved rounds. CPU was at 2.3-2.5 GHz and the APU at 12 W in every run.
Per thread group, pgo vs fpn:
So on the Deck the play profile does pay on top of #2235 at this size. My earlier 2560x1440 run had not shown it.
fps did not move: pgo 29.0, fpn 28.5, base 28.4 average. Median frame 33.8-34.3 ms in all three; every range holds 0.
On v3.2.0 at 1280x800 the Deck's frame is bound by the replay thread. Per-run medians over the window, all nine runs:
render_msdraw_ms14.2-15.9,cmds_ms6.4-7.1)main_blocked_msgame_msgpu_wait_msSo the CPU the two PRs save on the job workers does not reach the frame there. Next I'll try the recorder thread alone (
RX_VK_RECORDER=thread, Auto keeps it off at 4 cores) on thepgobuild, since the workers now leave more room on the 4 cores.Bench summary (per-run table, both A/B tables, clocks per run): deck-bench-v320-1280x800-pgo-fpn-base-summary.txt
Assisted-by: Claude
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.