perf(build): the hot pieces compile with their giant functions split #1146
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!1146
Loading…
Reference in a new issue
No description provided.
Delete branch "Marcuss2/Longshot:perf/build-split-hot-giants"
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: Linux (RADV, RX 9070 XT): the split build played in Kokiri Forest; game-free checks; the build measured from scratch · Needs: none
Why
A development build that carries a hot list (
A64_HOT_FUNCS) spends most of its compile on the hot pieces, and one of them is a single lifted function:code_hot_0.cisf_81b8c000, 4.79 MB of C, compiled at the hot-O2flags. On this PC it took 438 s of a from-scratch build's 446 s compile, so a build that carries a hot list took 8 min 26 s where one without takes about 3 min 20 s.The rest of the lift has had this fixed since
LONGSHOT_SPLIT_GIANTS(nx2/split_giants.py): a lifted function of 256 KB or more compiles as pieces cut at its labels, with a dispatcher under its own name, exact by construction. But the hot pieces' compile flags are built separately innx2/build.py(hot_fl) and never gotsplit_giants_flags(), so the hot giants were still compiled whole.What changed
The hot pieces now carry the same split flag as the lifted chunks. A 47-function hot-list build from scratch goes 8 min 26 s -> 3 min 19 s, and the exe is 896,056 bytes smaller.
nx2/build.py:hot_flags(fl)(new) builds the hot pieces' flags:flatRX_HOT_OPT(defaultO2) plussplit_giants_flags().main()calls it instead of the inline list, andsplit_fl's comment no longer says the hot pieces are left out.tests/test_hot_pieces_split.py(new): the source-level guard on those flags. It checks thathot_flags()carriessplit_giants.FLAG(default,RX_HOT_OPT=O1,LONGSHOT_SPLIT_GIANTS=0and=16), thatmain()takes itshot_flfrom it (so an edit back to the inline list fails), and thatsource_flags()sends acode_hot*file to it. The splitter's exactness is not re-proven:tests/test_split_giants.py(unchanged) proves it, and #1142 covers the hot path at-O2and-O1against-O2compiled.docs/development.md: theLONGSHOT_SPLIT_GIANTSrow says the hot pieces are split too, with the numbers; "A faster build for development" says the "about a third of the compile time" was before this.Measurements
Verdict: yes. From scratch with the real 47-function hot list: wall 8 min 26 s -> 3 min 19 s (-61%), compile 446 s -> 137 s (-69%), the single giant translation unit 438 s -> 56 s (-87%); the game exe 547,787,416 -> 546,891,360 bytes. An earlier pair the Lead measured on the same PC with the same list and the same one-line change gave 7 min 13 s -> 3 min 17 s (compile 369 s -> 138 s) and the same two exe sizes.
Hardware: Linux, AMD Ryzen 9 9950X3D (16 cores, 32 threads), 62 GB, NVMe
Scene: none (the build alone)
Method:
rm -rf build-linux && python3 -I scripts/dev_build.py build --out $PWD/build-linux/out-game, from scratch, withLONGSHOT_DEV_PYTHON,LONGSHOT_DEV_ROMFS,LONGSHOT_DEV_EXEFS,A64_HOT_FUNCS(the 47-function list) andLONGSHOT_OBJ_STORE=0 LONGSHOT_LIFT_STORE=0, shader preparation skipped (asdev_build.py builddoes), through the PC's job queue. Before: main @71b1edd8, one from-scratch build. After: this PR @d44ffb4c, two from-scratch builds (3 min 35 s and 3 min 19 s; the second is the table's). Three from-scratch builds in all, not interleaved (each is 3-8 minutes), and nothing else was building under the queue in those windows.How to reproduce: the command above, then the log's
code_hot_0.cline andthe build took ... compiled in ....71b1edd8d44ffb4ccode_hot_0.calonelongshotexeFlags and settings
None.
LONGSHOT_SPLIT_GIANTS(on by default at 8 KB) now coverscode_hot*.cas well;0still turns it off. Its row in docs/development.md is updated.Testing
Tested:
tests/test_hot_pieces_split.py: passes here; fails on main @71b1edd8withnx2/build.py has no hot_flags(): the hot pieces' flags carry no giant splitandmain() builds the hot flags with hot_flags(fl).tests/test_split_giants.py(unchanged): passes; it is the exactness proof for the splitter (random lifter-shaped functions, the real emitter's output, andcompile_one's copy, comparing the context, guest memory, page marks, calls, setjmp resumes and polls). #1142 adds the compiled hot path at-O2and-O1against-O2; this PR does not duplicate it.python3 -I -B tests/run_all.py --jobs 8: 587 passed, 17 failed, 74 skipped (8 at once, in 86 s). The 17 fail on main @71b1edd8on this PC too: test_audio_output_devices, test_bug_report, test_bug_report_defaults, test_crt_options, test_dlss_feature_size, test_failed_compile_keeps_objects, test_guest_imported, test_hardware_report, test_linux_preflight, test_linux_update, test_make_game_cache, test_missing_nup, test_mods_size_table, test_pending_guest_import, test_run_all_changed, test_vk_occlusion_queries, test_walk_key.Not tested: a Windows build with a hot list (the splitter and the flags are platform-neutral, and the game run above is on this PC's GPU and driver), and a release or player build (there is no hot list, so this path does not run). The exe is 0.9 MB smaller, so the code layout differs.
Must be tested: none. This is a build script's flags: the only thing that runs it is a home build with a hot list, which built and linked here and ran in the game above; releases ship no hot list.
Risks
What could break: a hot function whose text the splitter will not cut (a label inside a block, a computed goto, a top-level declaration) is left whole exactly as before, so a build cannot fail this way; the split's rules are the lifted chunks' already. The flag is in the object key, so the next build compiles the hot pieces again instead of taking an old object.
Turning it off:
LONGSHOT_SPLIT_GIANTS=0.Compatibility: nothing for players (a release has no hot list). A development build compiles its hot pieces again once, and the exe is 896,056 bytes smaller.
Issues
See #1142 (the compiled proof of the hot path at
-O2, and of-O1against-O2, open against main).Checklist
Everyone
type(scope): description) of the status line's type.main(71b1edd8).python -I -B tests/run_all.pypasses (the 17 failures also fail onmain; they are named above).third_party/untouched (a new folder with aPROVENANCE.mdinstead).When it applies
Assisted-by:/Co-Authored-By:trailers.mainand passing here.tests/that reads changed source updated in this PR, not weakened. (tests/test_hot_pieces_split.pyreadsnx2/build.py'shot_flagsandmain; no existing check needed updating.)Tested in game: Linux (RADV, RX 9070 XT, Ryzen 9 9950X3D), the split build with the 47-function hot list: Kokiri Forest at Link's house from the repo save, 40 s headless, 676 draws a frame, no crash, no assertion, 0 failed programs; split vs unsplit A/B over 10 interleaved arms: +0.24 % fps (exact permutation p = 0.43), -0.38 % CPU (p = 0.12), i.e. no measurable change.
Possibly related, for context:
WIP: perf(build): the hot pieces compile with their giant functions splitto perf(build): the hot pieces compile with their giant functions splitBot context (BeanIssues) names two open build PRs worth a line here: