perf(builder): the hot units' never-run blocks leave the hot code by default (LONGSHOT_HOT_SPLIT=0 turns it off) #2700
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/mods
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
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2700
Loading…
Reference in a new issue
No description provided.
Delete branch "klimovich008/Longshot:perf/hot-split"
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
The guest profile's text has no taken count for a branch that never jumped, so today such a branch has no weights at all and LLVM guesses where the side that never ran goes, often in the middle of the code that runs. In Market about 12,000 code pages of the exe run in every 50-100 ms, and only a little over a third of the hot units' guest instructions are in blocks that ran.
This is on by default now (HumanBean's question on this PR, answered yes by the maintainers).
LONGSHOT_HOT_SPLIT=0turns it off and gives the build without it exactly: main's IR and compile flags (386 of 386 unit texts identical to main's in a whole lift, from the earlier round). With it on, the lift weights every branch of the hot units that ran but never jumped(0, n). The compile then builds the hot units with LLVM's hot-cold splitting, but only for blocks behind such a branch (a probability of at most 2^-31). Block placement moves those never-run blocks to the end of each hot function, and LLVM moves a region out into acoldfunction of its own where it can (400 regions in the game, 55 KB). The code that runs every frame is denser. WithLONGSHOT_HOT_SPLIT=1the result was Market child +3.6 to +6.2 % fps and −4.4 to −6.6 % CPU ms over three rounds, every pair in favour.The switch:
1or any other word: on.0,off,no,falseor empty: off. The lift and the compile read it through one function (build_compile::hotsplit::on), so the two halves can't disagree.LONGSHOT_HOT_SPLIT_SKIP=<entries>still leaves functions out.longshot-builder compilechecks the lift'slift.keyagainst the switch under the new default: a lift made with the default compiles with the default; a lift made at0is refused by a compile with the default, and the other way round.longshot-builder dev liftnow reads the two switches as the build does;--hot-split,--no-hot-splitand--hot-split-skipoverride them.What the writer guards:
passes::splitmakes that block at the function's entry address.noinline, so it is never split.LONGSHOT_HOT_SPLIT_SKIPget no new zero weights.Read first:
builder/crates/build-compile/src/hotsplit.rs: the switch (on) and the flags.builder/crates/llvm/src/lib.rs:Module::split_cold,weights(),piece_start.builder/crates/lift/src/whole/mod.rs: the keys and thelift.keyline.builder/crates/build-driver/src/stages.rs:hot_splitandcheck_hot_split.Testing
Tested: Windows 11, Ryzen 7 5700X3D, RX 9070 XT, AMD 26.11.2 (LLPC). I built packs over main
9eabf8bc3withLONGSHOT_HOT_SPLIT=1and ran std_test A/Bs in Market child (and Lost Woods child once), plus single starts in Lost Woods, Fire Temple and Kokiri Forest. Every run reached its scene. No new error lines appeared in any game log (18 logs in round 1, every run since). No crash records.The default flip was not run again in the game or measured. Every number and game run here is from
=1. The default now takes the same code path as=1: both go through the same reading of the switch, and the new tests below check that unset gives what1gives.Checks on the latest head (the default flip, merged with main
20bedc6da):build-compilehotsplit2/2 (new:unset_is_on_and_an_off_word_is_off),liftthe_hot_split_is_in_the_key_only_when_on1/1, and thelongshot-builderintegration testhot_split6/6. The new test there,unset_is_on_and_0_is_off_in_the_lift_the_compile_and_the_compile_s_check, covers the lift's half, the compile's half and the standalone compile's check of a lift made unset, at0, or with nolift.key.cargo fmt --all --check,cargo clippy -D warningson the changed crates andmise run lintare clean.Checks from the rounds before, with
=1:tests/run_all.py(Windows): 793 passed, 17 failed, 51 skipped; all 17 fail on main455b143bon this PC too.llvm17/17,lift47/47.build-compileandbuild-driverhave 10 Windows path and toolchain failures, the same ones main has on this PC.compilerefuses a lift made with the switch the other way, or a bad skip list.tests/test_lifter_semantics.py: the new--hot-flags(compile as a hot unit) and--hot-split(the writer) are ok against Unicorn at x86-64-v2 and v3, with 3,561 outlined cold functions each.Still to test:
LONGSHOT_HOT_SPLIT=0against the default, expecting fewer CPU ms with the default (by hand, or the Test Farm).Measurements
All measured with
LONGSHOT_HOT_SPLIT=1, before the default flip.Verdict: Market child +3.6 to +6.2 % fps and −4.4 to −6.6 % CPU ms in three 3-pair A/Bs, all 9 pairs in favour. Lost Woods child +2.5 % fps, CPU flat. Market's 3-pair noise is about 3 % fps and 5 % CPU ms, so each A/B alone is close to it; the three agree.
Setup: Windows 11, Ryzen 7 5700X3D, RX 9070 XT, AMD 26.11.2. Uncapped (
HOS_FPS_MAX=240), 16:9, render thread on, the fixed test profile. std_test's 20 s window after the teleport, 3 alternating pairs per A/B, with the background GPU load. Medians. Every contained game-clock reading was 0.989-1.011.Market child:
9eabf8bc3c17ccc776d4d0f25f6): fps, CPU ms, p99Lost Woods child (round 1): 121.44 → 124.44 fps (+2.5 %), 39.83 → 39.73 CPU ms (flat), p99 11.02 → 11.72.
The A/Bs ran on main
9eabf8bc3. The PR is now on main20bedc6da. The commits since then change none of the lifter, the IR writer or the compile of the lifted units. One of them (#2665, mutex lookups through the guest word) changes the host's CPU work in both arms alike. The A/B was not run again.LONGSHOT_NO_CLANGin the diff is the builder tests' existing escape (no clang on the runner: the clang checks pass over), used by the new integration test as by the others, not a switch the build reads.Costs:
Risks
LONGSHOT_HOT_SPLIT=0gives the build without the splitting: main's IR and compile flags, and the keys this lifter gives without it. Setting it or clearing it lifts and compiles the hot units alone again.(0, n). LLVM folds the jump block, so in synthetic IR that zero edge could reach the join and mark it cold.ran..pdata(Win64 allows it), so the host sampler's stack walk stops at one; the crash recorder's leaf rule handles them.scripts/profiling/cpu.pydoesn't mapf_X.cold.Nnames to their guest function.--split-over) keys a piece start's counts at the entry.compileatLONGSHOT_HOT_SPLIT=0accepts a gen/ with nolift.keyand kept IR, as main's does.Turn it off:
LONGSHOT_HOT_SPLIT=0, or revert.Checklist
Ready for review
main; the title is a Conventional Commit.=1; the default flip runs the same code and was checked by the tests above.mise run testpasses (any failure that also fails onmainis named).tests/run_all.pyon Windows, before the flip: 793 passed, 17 failed, 51 skipped; the same 17 fail on main455b143bon this PC: test_auto_handheld.py, test_builder_channel.py, test_control_picture.py, test_coverage_run.py, test_crash_record.py, test_dev_ab.py, test_dev_build.py, test_dev_migrate.py, test_fs_path_utf8.py, test_job_queue.py, test_longshot_ctl.py, test_oot_menu_mouse.py, test_oot_state_tap.py, test_parity_gates.py, test_run_all_mingw.py, test_screensaver.py, test_switch_table.py.main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
gpu/vk/switches.def. It's a build switch, on by default: its row,LONGSHOT_HOT_SPLIT=0, is indocs/dev/reference/build.md's table, notswitches.def.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.🤖 Generated with Claude Code
Tested in game: Windows 11, Ryzen 7 5700X3D, RX 9070 XT, AMD 26.11.2 (LLPC): packs with LONGSHOT_HOT_SPLIT=1 over main
9eabf8bc3, std_test A/Bs in Market child (three rounds, 3 pairs each) and Lost Woods child, single starts in Lost Woods, Fire Temple and Kokiri Forest. Every run reached its scene; no new error lines in the game logs; no crash records. Market child +3.6 to +6.2 % fps, -4.4 to -6.6 % CPU ms.Possibly related, for context:
@review
Recommendation: Approve. The new integration test ignores the configured compiler and can fail on supported setups that provide Clang through CC. The reported Market gain is promising, but Linux and Steam Deck behavior and the effect in other scenes remain unmeasured. Nothing blocking is left: what remains is for the author before merging (below). Recommend approval; not approved on the forge.
The opt-in switch moves profile-cold regions of hot lifted functions out of their hot code. On the reported Windows PC, Market improved by 3.6–6.2% FPS across three A/B rounds, at the cost of a larger executable and a one-time lift-key change for everyone.
Should fix (1): not blocking, but worth doing before merging.
builder/crates/longshot-builder/tests/hot_split.rs:19: The integration test selects only hard-coded Clang names and ignores CC. (more on the line) Do: Honor CC when selecting the compiler, with the existing Clang discovery as a fallback, and preserve the explicit no-Clang skip behavior.Testing before merging (2) (runs on the systems it can change; it doesn't hold the recommendation)
builder/crates/build-compile/src/hotsplit.rs:15: The changed CPU code has only been measured on one Windows CPU; its effect on Linux, Steam Deck and smaller caches remains unknown. (more on the line) Do: Run interleaved switch-off/on comparisons in Market on Linux or Steam Deck and a smaller-cache CPU, including FPS, lows and frame times; exercise additional scenes with the switch enabled. (@fixdoes its part first: The switch is already off by default; retain that default until the broader results support changing it.)builder/crates/lift/src/whole/mod.rs:460: The build measurements cover hot-unit compile CPU time but not the full clean build or the incremental one-function-change build. (more on the line) Do: Compare clean and one-function-change build elapsed times and output sizes against the base, including the default-off first rebuild.@fixcan do L1 and L2.Checks: Still running: 8 checks.
More: does it help, other systems, switches, what was read
Does it help: Unproven across supported systems. The author's Windows Market measurements show 3.6–6.2% higher median FPS and 4.4–6.6% lower CPU time, but the third round's p99 rose from 17.72 to 18.15 ms; Lost Woods FPS rose 2.5% with CPU time flat and p99 rising from 11.02 to 11.72 ms. Linux, Steam Deck and other CPUs have not been measured.
Other systems: The switch changes generated CPU code on Windows and Linux regardless of GPU vendor. Different CPUs and routes can execute profile-cold regions frequently; the reported runs cover one Windows CPU and a few scenes. With the switch off, changed lifter sources still invalidate lift keys once for existing players.
Switches: LONGSHOT_HOT_SPLIT defaults off; that is appropriate while broader results are pending. LONGSHOT_HOT_SPLIT_SKIP defaults empty and is read only when splitting is on; it is a developer escape hatch. Both are documented in the build switch table. The new dev lift and words flags and semantics-test flags also default off.
Reviewed:
200d3741beagainst1f83583528: Read AGENTS.md, CONTRIBUTING.md, the pull request template, standards, the diff, commit messages, the new hot-split integration test and LLVM hot-split tests, and the relevant lift session and LLVM writer paths. Skimmed the remaining changed files and surrounding callers; not every changed code file was read in full. docs/review-checklist.md and ../Tooling/AGENTS.md were absent. No recorded run artifacts, translations or generated files were included in the diff.; nothing run (a code review).Checked and fine:
Testing: No commands that build, test or run project code were executed. The author's Windows game runs and reported crate and integration-test results were considered; CI was still running.
Overlaps and merge order: Unknown; the network is closed.
Automated code review by BeanBot (gpt-6.1-terra), asked for by klimovich008. Nothing was run; a maintainer decides.
@ -0,0 +12,4 @@/// probability at most 2^-31, a branch the profile never saw taken (LLVM's default, 1 %, would also take blocks that/// ran). A call of a `cold` function (a float's slow path) still makes its block cold, whatever the probability.pub fn flags(on: bool) -> Vec<String> {if !on {L2 (should fix): The changed CPU code has only been measured on one Windows CPU; its effect on Linux, Steam Deck and smaller caches remains unknown.
When: With the switch enabled on a different CPU or route, a region absent from the guest profile can be executed frequently and pay the outlined-call and layout costs.
Do: Run interleaved switch-off/on comparisons in Market on Linux or Steam Deck and a smaller-cache CPU, including FPS, lows and frame times; exercise additional scenes with the switch enabled.
@ -431,0 +457,4 @@let mut text = format!("{}\n{}\n{} {:?}", program.inputs(entry), s.edits.key(entry), r.cold, r.counts);// (a hot function's unit is made for hot-cold splitting with the switch: its key says so, and whether the// skip list names it; the other units' texts, and so their keys, are the same either way)if let Some(skip) = s.o.hot_split.as_ref().filter(|_| hot.contains(&entry)) {L3 (should fix): The build measurements cover hot-unit compile CPU time but not the full clean build or the incremental one-function-change build.
When: Every existing player gets new lift keys when these lifter sources ship, so the one-time rebuild can add elapsed time even with the switch off.
Do: Compare clean and one-function-change build elapsed times and output sizes against the base, including the default-off first rebuild.
@ -0,0 +16,4 @@/// The clang the test compiles with (that of the PATH; `LONGSHOT_NO_CLANG=1` passes over the test without one).fn clang() -> Option<&'static str> {let found = ["clang", "clang-23"]L1 (should fix): The integration test selects only hard-coded Clang names and ignores CC.
When: On a supported build machine where CC points to a suitable Clang at another path or name and neither clang nor clang-23 is on PATH, the new test panics instead of using the configured compiler.
Do: Honor CC when selecting the compiler, with the existing Clang discovery as a fallback, and preserve the explicit no-Clang skip behavior.
Answers to BeanBot's review of
200d3741b:8b992fd06.tests/hot_split.rstakesCCfirst when it names a compiler that runs, thenclangandclang-23;LONGSHOT_NO_CLANG=1still passes over it. Checked withCCset to llvm-mingw's clang by its full path and no clang on the PATH: 5 of 5.Measured on main
9eabf8bc3; the PR is now on main1f8358352. The 17 commits since change none of the lifter, the IR writer or the compile of the lifted units (one, #2665, changes the host's mutex lookups in both arms alike), so the A/B wasn't run again.Should we enable by default?
@review
Recommendation: Approve. The opt-in change shows a Windows Market gain, but its effect on Linux, Steam Deck and smaller caches remains unknown, as does its full build-time cost. Keep it off by default until broader results support enabling it. Nothing blocking is left: what remains is for the author before merging (below). Recommend approval; not approved on the forge.
The builder can use profile weights and LLVM hot-cold splitting to make frequently executed game code denser. It adds an opt-in build path and causes a one-time lift-key change for existing builds.
Should fix (1): not blocking, but worth doing before merging.
builder/crates/longshot-builder/tests/hot_split.rs:23: The compiler probe accepts any executable that succeeds with --version, including compilers that cannot compile LLVM IR. (more on the line) Do: Verify that the CC candidate is a suitable Clang compiler before selecting it, and fall back to the PATH candidates otherwise.Testing before merging (2) (runs on the systems it can change; it doesn't hold the recommendation)
builder/crates/build-compile/src/hotsplit.rs:15: The changed CPU code has only been measured on one Windows CPU; its effect on Linux, Steam Deck and smaller caches remains unknown. When: With the switch enabled on a different CPU or route, a region absent from the guest profile can be executed frequently and pay the outlined-call and layout costs. Do: Run interleaved switch-off/on comparisons in Market on Linux or Steam Deck and a smaller-cache CPU, including FPS, lows and frame times; exercise additional scenes with the switch enabled. (@fixdoes its part first: The switch is already off by default; retain that default until the broader results support changing it.)builder/crates/lift/src/whole/mod.rs:460: The build measurements cover hot-unit compile CPU time but not the full clean build or the incremental one-function-change build. When: Every existing player gets new lift keys when these lifter sources ship, so the one-time rebuild can add elapsed time even with the switch off. Do: Compare clean and one-function-change build elapsed times and output sizes against the base, including the default-off first rebuild.@fixcan do L2 and L4.Since the last review (on
200d3741be)Resolved: L1 (The integration test selects only hard-coded Clang names and ignores CC.)
Still open: L2 (The changed CPU code has only been measured on one Windows CPU; its effect on Linux, Steam…); L3 (The build measurements cover hot-unit compile CPU time but not the full clean build or the…)
New: L4 (The compiler probe accepts any executable that succeeds with --version, including compiler…)
Checks: Still running: 7 checks.
Also noticed (2; not asked for, not blocking)
More: does it help, other systems, switches, what was read
Does it help: Yes on the tested Windows PC: the PR reports three Market A/B medians of +3.6% to +6.2% FPS and −4.4% to −6.6% CPU time. The measurements used an earlier main commit, and results elsewhere remain unproven.
Other systems: The switch changes lifted CPU code on Windows and Linux when enabled. Linux, Steam Deck, smaller-cache CPUs and additional scenes remain untested; the author reports Windows game runs and matching lifted behavior in an integration test.
Switches: LONGSHOT_HOT_SPLIT defaults off; retaining that default is appropriate pending broader results. LONGSHOT_HOT_SPLIT_SKIP defaults to an empty list and excludes named functions when splitting is enabled. LONGSHOT_NO_CLANG is an existing test escape, not a new build switch.
Reviewed:
8b992fd06dagainst1f83583528: Read the changed integration test in full, the fix diff, build-compile hotsplit flags, relevant lift and driver references, repository rules and PR template. Skimmed the overall diff and commit list; the remaining changed code and recorded tests were not read in full.; nothing run (a code review).Checked and fine:
Testing: No commands from the project were run. The author reports Windows game and integration-test results; CI is still running.
Overlaps and merge order: Not checked; the network is closed.
Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
@ -0,0 +20,4 @@let found = std::env::var("CC").ok().into_iter().chain(["clang".to_string(), "clang-23".to_string()])L4 (should fix): The compiler probe accepts any executable that succeeds with --version, including compilers that cannot compile LLVM IR.
When: With CC=gcc and clang available on PATH, gcc is selected first; the tests then pass it Clang-specific options and LLVM IR and fail instead of falling back to clang.
Do: Verify that the CC candidate is a suitable Clang compiler before selecting it, and fall back to the PATH candidates otherwise.
WIP: perf(builder): LONGSHOT_HOT_SPLIT=1, the hot units' never-run blocks leave the hot code (off by default)to WIP: perf(builder): the hot units' never-run blocks leave the hot code by default (LONGSHOT_HOT_SPLIT=0 turns it off)@HumanBean: yes. It is on by default now, in
af570e01a(merged with main20bedc6dafirst, no conflicts).1or any other word is on;LONGSHOT_HOT_SPLIT=0(oroff,no,false, empty) is the kill switch and gives main's IR and compile flags. The lift and the compile read it through one function,build_compile::hotsplit::on.lift.keyfollows the new default: a lift made with the default compiles with the default; a lift made at0and a compile with the default (or the other way round) is refused with "lift again".LONGSHOT_HOT_SPLIT=1, which the default now equals. New test:unset_is_on_and_0_is_off_in_the_lift_the_compile_and_the_compile_s_checkintests/hot_split.rs, plushotsplit'sunset_is_on_and_an_off_word_is_off.BeanBot's L4 (the CC probe accepted gcc): fixed in
af570e01a.CCis taken only when its--versionsaysclang version; otherwise the test falls back toclangandclang-23on the PATH. L2 and L3 stay as they were: Linux, the Steam Deck and smaller caches are in Still to test.@review
Recommendation: Approve. The code is ready: only testing is left. The Windows measurements show a Market gain, but the now-default optimization still needs the Linux, Steam Deck and smaller-cache measurements requested in L2. Clean and incremental build times also remain unmeasured. Recommend approval; not approved on the forge.
The builder moves profile-cold regions out of hot functions by default, improving measured Market performance at the cost of a one-time lift and recompilation of hot units after updating. The shared switch reader keeps the lift and compile defaults aligned.
Testing before merging (2) (runs on the systems it can change; it doesn't hold the recommendation)
builder/crates/build-compile/src/hotsplit.rs:15: The optimization is now enabled by default without measurements on Linux, Steam Deck or smaller-cache CPUs. When: Those players receive the changed code layout, but its performance relative to the disabled build is unknown. Do: Run matched, repeated default-versus-0 game A/Bs on Linux, Steam Deck and a smaller-cache CPU. (@fixdoes its part first: The switch is already off by default; retain that default until the broader results support changing it.)builder/crates/lift/src/whole/mod.rs:460: The build measurements cover hot-unit compile CPU time but not the full clean build or the incremental one-function-change build. When: Every existing player gets new lift keys when these lifter sources ship, so the one-time rebuild can add elapsed time even with the switch off. Do: Compare clean and one-function-change build elapsed times and output sizes against the base, including the default-off first rebuild.@fixcan do L2.Since the last review (on
8b992fd06d)Resolved: L4 (The compiler probe accepts any executable that succeeds with --version, including compiler…)
Still open: L2 (The optimization is now enabled by default without measurements on Linux, Steam Deck or sm…); L3 (The build measurements cover hot-unit compile CPU time but not the full clean build or the…)
Checks: Failing on this head, which is behind its base, where it passes:
CI / Third-party parts and guide screenshots (pull_request).@rebase(or@fix) brings it up to date and runs it again; not held against it. Still running: 7 checks.Also noticed (1; not asked for, not blocking)
More: does it help, other systems, switches, what was read
Does it help: Yes on the tested Windows PC: three Market A/B rounds reported 3.6–6.2% higher median FPS and 4.4–6.6% lower CPU time. The effect on Linux, Steam Deck and smaller-cache CPUs remains unproven.
Other systems: The changed native code runs on Windows and Linux across CPUs; only one Windows CPU was measured. The author reports Windows and Linux target integration checks and game starts in four scenes, but no Linux or Steam Deck game run.
Switches: LONGSHOT_HOT_SPLIT now defaults on; 0, off, no, false or empty disables it. The default still needs broader measurements. LONGSHOT_HOT_SPLIT_SKIP excludes named functions and defaults to an empty list; dev lift now reads both environment switches and permits command-line overrides.
Reviewed:
af570e01a8against20bedc6da1: Read AGENTS.md, CONTRIBUTING.md, the pull request template, the changed switch implementation, compiler probe, lift keys and LLVM changes; inspected the relevant diff and callers. Other changed files and tests were skimmed, not read in full.; nothing run (a code review).Checked and fine:
Testing: No commands from the project were run. The author reports game runs and integration checks; CI is still running.
Overlaps and merge order: Not checked; network access is unavailable.
Automated code review by BeanBot (gpt-6.1-terra), asked for by klimovich008. Nothing was run; a maintainer decides.
WIP: perf(builder): the hot units' never-run blocks leave the hot code by default (LONGSHOT_HOT_SPLIT=0 turns it off)to perf(builder): the hot units' never-run blocks leave the hot code by default (LONGSHOT_HOT_SPLIT=0 turns it off)Out of WIP at
af570e01a, as the maintainer asked: on by default,LONGSHOT_HOT_SPLIT=0turns it off, and the standalone compile'slift.keycheck follows the new default. The edited tests pass (build-compile hotsplit 2/2, the lift key test 1/1,tests/hot_split.rs6/6). fmt, clippy on the touched crates andmise run lintare clean. Not retested in the game: the measurements are from=1builds. CI was still running when I took it out of WIP. The guide screenshot check fails on main's head too, on 7 menu files changed by #1349 and #2708 without a review; this PR touches no third_party/ file and no guide picture.🤖 Generated with Claude Code