perf(build): the hot code compiles within memory with no profile, its giant functions first #791
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 @ 1697603
beanstalk: approved @ 2c5a62e
beanstalk: approved @ 4fd82b7
beanstalk: approved @ 64d6d09
beanstalk: approved @ 6f91fae
beanstalk: approved @ 70a78f9
beanstalk: approved @ 8015c9a
beanstalk: approved @ 8d361dc
beanstalk: approved @ 9d8356e
beanstalk: approved @ abf2227
beanstalk: approved @ d82f202
beanstalk: approved @ e5f1e40
beanstalk: approved @ ee8ab5f
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
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
testing wanted
ci: approved
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!791
Loading…
Reference in a new issue
No description provided.
Delete branch "dyst/Longshot:perf/hot-compile-guard"
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?
Type: perf · Risk: low · Tested on: Windows 11 (game-free checks) · Needs: a full build with and without
longshot_pieces.prof, on a 16 GB PCWhy
A build whose hot code has no matching play profile can run out of memory. That's an instrumented build (
RX_PGO=gen), a player's build withlongshot_pieces.profmissing or unreadable, or any function the profile no longer matches after a lift change. Project ReLink, a fork of Longshot, found that the hot code's vector float functions of about 2 MB of C then took one compiler past 15 GB. They also found that those giant functions, started last, stretch the hot compile by minutes (eeab6b58).What changed
Two changes to the hot pieces' compile, from ReLink's commit.
nx2/build.pyadds-mllvm -disable-hoisting-to-hotter-blocks=allto the hot pieces' flags in everyRX_PGOmode.nx2/split_hot.pycounts a function of over 2 MB of C 2.2 times in its piece's cost, sobuild.py, which starts the costliest first, starts that piece first. Only the order changes; the pieces are the same.tests/test_hot_compile_guard.py(new) checks the flag's place in every mode and only on the hot pieces. It also runssplit_hoton made-up functions, one over 2 MB, and checks each piece's cost and that the giant's piece is the costliest.Measurements
Verdict: game-free only: the hot pieces now carry the flag in every
RX_PGOmode and a function of over 2 MB of C counts 2.2 times in its piece's cost, where main has neither; the build's time and memory are not measured on Longshot (Must be tested).Hardware: Windows 11 Pro, Ryzen 9 3900X, 64 GB; llvm-mingw clang 23.1.5 (the Builder's v2.0.14 tools)
Scene: none (a build change, game-free, no dump)
Method:
tests/test_hot_compile_guard.pyon this PR's tree and with main'snx2/build.pyandnx2/split_hot.py; a case passes or not, so there is nothing to take a median ofHow to reproduce:
python -I -B tests/test_hot_compile_guard.pyhere, and the same file copied into a checkout of main1310ecc6314cf860-mllvm -disable-hoisting-to-hotter-blocks=allon the hot pieces, everyRX_PGOmodechunk_costs.txt)ReLink's numbers, for the same lift (not a Longshot claim):
What to measure on Longshot: a build's hot compile, its time and its compilers' peak memory, with and without
longshot_pieces.prof, on main and on this PR.Flags and settings
None: a compiler flag on the hot pieces, no switch.
Testing
Tested:
tests/test_hot_compile_guard.py(2 tests) on this branch @314cf860: passes; with main's files @1310ecc6: fails (Measurements).python -I -B tests/run_all.py --jobs 6 --exactwith the checks undertests/andnx2/test_*.pythat name a changed file, and the ones it adds or changes), not the whole suite, on this branch @314cf860(rebased onto main @1310ecc6), Windows 11 Pro, with the Builder's llvm-mingw clang (the v2.0.14 tools): 35 passed, 6 failed, 1 skipped (a tool this PC lacks). The 3 that fail also fail on main @1310ecc6(the whole suite there: 500 passed, 17 failed): test_appimage_player_build, test_linux_preflight, test_vk_pgo. test_dll, test_driver_cache_folder, test_pipeline_tour are skipped on Windows in a whole run (Linux-only or a full game build); named, as here, they fail on main @1310ecc6too. The checks: test_dll, test_appimage_licenses, test_appimage_player_build, test_bake_ds, test_bake_skeleton, test_build_cleanup_scope, test_build_hash_cache, test_build_times, test_compile_retry_jobs, test_compiler_failure, test_cpm_discovery, test_cpu_target, test_dev_packs, test_dlss_sdk_cache, test_driver_cache_folder, test_exclusive_marks, test_failed_compile_keeps_objects, test_fpx_sticky, test_hot_compile_guard, test_kept_translation, test_late_fix_build, test_lift_cache, test_link_path_comma, test_linux_preflight, test_make_game_ngx, test_mem_gate, test_mem_gate_children, test_mem_gate_leases, test_mem_limit, test_pipeline_tour, test_prepare_at_build, test_program_cache_format, test_recorder_sync, test_shader_stamp_cache, test_shader_stamp_inputs, test_split_giants, test_stale_hot_pieces, test_sticky_hot_pieces, test_switches_removed, test_third_party_objects, test_utf8_paths, test_vk_pgo.-mllvm -disable-hoisting-to-hotter-blocks=all(a compile of a test file).Not tested:
Must be tested:
A 16 GB PC, any OS:
work/longshot_pieces.profaside).Expect the second build's hot compile to finish without running out of memory, and the giants' pieces among the first started (
build_times.json) (by hand).Risks
What could break: the hot pieces' flags change, so every build compiles the hot code again once (its object keys hash the flags), and a player whose last build kept its translation (
--kept-lift) has the game translated again once too:kept_partis made from the same flags, so the kept list no longer fits (KEPT_STALE,nx2/build.py). With no profile, some hot loops may run a little slower where the hoisting helped. With a matching profile nothing should change.Turning it off: revert the commit.
Compatibility: the next build compiles the hot pieces again, and translates the game again once where the last build kept its translation (
KEPT_STALE, as with #660's key change: landing both in one release costs one translation). Saves, the options file, the shader and pipeline caches and the vk ABI are unchanged.Checklist
Everyone
type(scope): description) of the status line's type.main.python -I -B tests/run_all.pypasses (any failure that also fails onmainis named).third_party/untouched (a new folder with aPROVENANCE.mdinstead).When it applies
Assisted-by:/Co-Authored-By:trailers.mainand passing here.🤖 Generated with Claude Code
625b9e8aab314cf860f9Rebased onto main @
1310ecc6(head314cf860, no conflicts; it also merges cleanly with main @7bacf846). The 42 checks that read this diff, not the whole suite (the agreed process now): 35 passed; the 3 that fail also fail on main @1310ecc6, and 3 Linux-only or game-build checks, skipped on Windows in a whole run, fail when named on main too (listed under Testing). Measurements now has the game-free comparison (test_hot_compile_guard on main and here). Description fix: Risks and Compatibility now say that a player whose last build kept its translation (--kept-lift) gets the game translated again once, since kept_part hashes the hot flags (KEPT_STALE), as #660 says of its own key change.WIP: perf(build): the hot code compiles within memory with no profile, its giant functions firstto perf(build): the hot code compiles within memory with no profile, its giant functions firstView command line instructions
Checkout
From your project repository, check out a new branch and test the changes.