perf(build): the chunks an all-O2 build compiles are cut into parts #1431
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 project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!1431
Loading…
Reference in a new issue
No description provided.
Delete branch "Marcuss2/Longshot:perf/build-o2-chunks"
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) · Needs: none
Why
LONGSHOT_CHUNK_OPT=allbuilds every lifted chunk at-O2. A 25 MB chunk's-O2passes cost more than linearly in itsfunctions' sizes (GVN alone was 43-46% of one chunk's compile here), and 32 of them at once contend for memory
bandwidth: from scratch on one lift the build took 23:06, its longest single compile 960 s. The lift already splits a
chunk whose cost is past a plain one's (
chunks.split_big); this splits it again where the build compiles it.What changed
The build cuts each chunk it sends to
-O2at function starts into parts of aboutLONGSHOT_CHUNK_PART_MB(6) MB ofestimated compile cost, each with the chunk's declarations and each its own object. The lifted C is not changed; the
parts are written to
<build>/splitwith a stamp, so a build that changed nothing writes nothing.--kept-liftbuildsare not cut.
LONGSHOT_CHUNK_LEVEL(defaultO2;O1,O2orO3) is the level those chunks compile at.nx2/build.py:chunk_opt_o2(the selection),chunk_levelandchunk_flags(the level, no light flags),chunk_parts(the cut,chunks._cut),chunk_split_flag(the cut in the object key);mainexpands a selectedchunk's job into its parts and skips
write_keptfor a cut build.docs/development.md: the three switches and "An all-O2 build".tests/test_chunk_parts.py: the cut, the functions and declarations, the stamp, the selection and the levels, game-free.Measurements
Verdict: yes. Against main's default (the hot list's functions at
-O2, the rest-O1), the all-O2build is+4.4% fps at Link's house for +2:03 of build; the cut is what makes that build 5:00 instead of 23:06 (whole
chunks).
-O3is within noise of-O2in the scene and costs the same build time.Main's default is not all-
O1: the lift puts the hot list's functions incode_hot_*.c, compiled at-O2. Thecomparison uses the 47-function list from the opt-budget report (the shipped profile is not in this checkout; the
shipped list is larger, which would make main's default a little slower to build and a little faster in the game, but
not change the direction).
A three-way run on the PR's base: main @
67efc4d3, the same lift (89 files, 1.4 GB of C, 8 hot pieces), the same PC,one build at a time, from scratch in a fresh work folder.
Hardware: Linux, AMD Ryzen 9 9950X3D (16 cores, 32 threads), 62 GB, NVMe, RADV RX 9070 XT.
Scene: none (the build alone).
Method:
OOT_WORK=<work> [LONGSHOT_CHUNK_OPT=all [LONGSHOT_CHUNK_LEVEL=O2|O3 [RX_HOT_OPT=O3]]] python3 -I nx2/build.py --standalone --jobs 32,nothing else running.
How to reproduce: from a fresh work folder with the hot-list lift (
OOT_WORK=<work>), run the Method line on main forthe first column, and on this branch with
LONGSHOT_CHUNK_OPT=allandLONGSHOT_CHUNK_LEVEL=O2orO3for theothers. The logs are
hot-main.log,hot-o2.logandhot-o3.login the checkout'swork/investigations/(notcommitted: build output).
67efc4d3, default (hot pieces-O2)c2f3e5b5,-O2c2f3e5b5,-O3longshotThe cut's own effect, measured on
544229a2without a hot list: the same all-O2build without the cut (whole chunks)took 23:06 (compile 1,384 s, 31,675 s of lifted compiles, longest 960 s), and with the cut 4:37 (268 s, 7,859 s,
longest 91 s). The hot list adds its own pieces at
-O2(226-250 s here).The per-chunk probe (one compile at a time):
code_022.c133 -> 87 s in 4 parts (its longest compile 133 -> 28 s),code_008.c162 -> 73 s,code_000.c39 -> 26 s; the objects are the same size.In the game
Link's house (the repository save
kokiri-start), standing still, 20 s warm-up then the control bridge's fps once asecond for 40 s; four interleaved runs each, the median of the 160 samples. Same PC, 2560x1440, the game's own
upscaler,
HOS_DYNRES=0,HOS_FPS_MAX=1000, headless, audio off.67efc4d3, hot pieces-O2c2f3e5b5,-O2c2f3e5b5,-O3The all-
O2build is 4.4% faster than main's default;-O3is within noise of it (0.0%). The first runs of the sessionwere slower (the GPU's clocks ramp): the interleaved later runs are main 92.9,
-O295.8,-O395.8. The runs hadoccasional hitches (12.8-45.4 fps in one sample), which the median ignores.
Flags and settings
Three build switches, all compile-only and off by default:
LONGSHOT_CHUNK_OPT=allor<file>-O2/-O3LONGSHOT_CHUNK_LEVEL=<level>O1,O2orO3; defaultO2)O2-O3gives no fps over-O2hereO2;O3only for a scene A/BLONGSHOT_CHUNK_PART_MB=<MB>0: whole chunks)Testing
Tested:
python3 -I -B tests/run_all.py --jobs 8: 609 passed, 36 failed, 77 skipped; the same failures (and 2 more)fail on clean
origin/main@544229a2here (606 passed, 38 failed), so no new failure.tests/test_chunk_parts.pypasses. In the game (Linux, RADV, RX 9070 XT), Link's house from the repository save
kokiri-start, standing still:91.8 fps on main's default (hot list at
-O2), 95.8 on this branch at-O2and 95.8 at-O3(four interleavedruns each, the median of 160 samples); no crash or assertion. The three
docs/tested/files have the runs.Not tested: Windows.
Must be tested: none.
Risks
What could break: the parts compile to the same functions but the inliner sees one part at a time, so the code
layout differs slightly (the exe is 23.5 MB smaller at
-O2, 11.3 MB larger at-O3than main's default). The hotpieces are not cut, so the game's hot path is unchanged. A chunk whose text the cut refuses stays whole.
Turning it off:
LONGSHOT_CHUNK_PART_MB=0(or unsetLONGSHOT_CHUNK_OPT).Compatibility: nothing for players:
LONGSHOT_CHUNK_OPTis opt-in, and a release build sets neither switch.Checklist
Everyone
type(scope): description) of the status line's type.can't be run by hand is in Testing's Not testable by hand, with why.
in Risks.
main(67efc4d3).python -I -B tests/run_all.pypasses (the failures are pre-existing; 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.Tested in game: Linux, RADV, RX 9070 XT: the parts build ran headless at the title, 6,885 frames in 30 s, no crash or assertion
b396651895db06875203db06875203c3cfa11a46WIP: perf(build): the chunks an all-O2 build compiles are cut into partsto perf(build): the chunks an all-O2 build compiles are cut into partsAdded LONGSHOT_CHUNK_LEVEL and the three-way comparison on
67efc4d3: main -O1 2:34, this branch -O2 4:29, -O3 4:34; -O3 is 5 s more than -O2 for +8 MB of exe. Both -O2 and -O3 ran headless at the title, 6,885/6,890 frames in 30 s, no crash.Thanks this is great work, we'll look into this!
FPS benchmark of the three builds at Link house (repo save kokiri-start), two interleaved runs each, median of 80 samples: main 86.9, this branch -O2 91.9, -O3 92.8 fps. -O2 is +5.8% over main, -O3 +1.0% over -O2. Three docs/tested files added (commit
4ab8eafb).Correction: main default is not all -O1. Rebuilt all three on a lift with the hot list (47 functions, the opt-budget list; the shipped profile is not in this checkout): main default 2:57 build / 91.8 fps, this branch -O2 5:00 / 95.8 fps, -O3 5:00 / 95.8 fps (four interleaved runs each). So the all-O2 build is +4.4% fps over main default for +2:03 of build; -O3 is within noise. The docs/tested files are updated (commit
ef82c5a5).Brought up to the ready-for-review standard (#1454): the checklist's Everyone list has two new boxes, added here from what this PR's description and comments show (please check they match what you know).