perf(build): lifted chunks with small functions compile without -O1's module passes (LONGSHOT_LIGHT_PASSES, on by default) #1002
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
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!1002
Loading…
Reference in a new issue
No description provided.
Delete branch "madebyjordan/Longshot:perf/light-passes"
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, RX 6700 XT (Ryzen 5 5600, 6 cores) · Needs: a 4-core PC or a Steam Deck (game-thread CPU, main against this PR)
Why
A player's first build spends most of its time compiling the game's code, which the lift turned into C. Most of that
code is ordinary functions, and clang's
-O1runs a group of whole-file passes over them (the inliner, constantpropagation across functions, function attributes ...) that do little for this code. Without them those files compile
about a fifth faster. This PR turns that on by default for the ordinary files and keeps every pass for the rest.
See #362 (a first build in under 10 minutes).
What changed
Lifted chunks whose functions are all under 1 MB compile at
-O1without its module passes (-mllvm -opt-disable=...).The size test is on the lifted functions, so where
LONGSHOT_SPLIT_GIANTScuts some of them into pieces, the piecescompile light too. The giant functions (1 MB or more), the hot pieces and every non-lifted file keep their flags. The
lifter's header helpers are all
always_inlinenow, so the inliner's absence leaves none of them as a call.nx2/build.py:LIGHT_FLAGS, andlight_passes_kb(), the size bar: the largest lifted function must be underLONGSHOT_LIGHT_PASSES_KB, 1024 KB by default.lifted_flags, andsource_flags: the per-source choicemain()made inline (hot pieces, lifted chunks, the rest),moved into a function.
largest_function: the function-size scanmem_needalready had, now shared.lifted_largestkeeps each lifted file's largest function in the hash record (hash_cache.json,load_hashes), soa build that already knows a file doesn't read it again.
object_key,flag_text), so the object cache and the object storenever mix a light object with a full one.
light_flags_work: one tiny compile asks the compiler first.-opt-disableis LLVM 22's, and a Linux build fromsource may use the system's older clang (the README says it builds), which stopped every light chunk with "Unknown
command line argument". With such a compiler the build prints a line saying so and every lifted chunk keeps main's
flags.
third_party/a64-kit/lift/a64_lift.py:a64_v_ult,abs,big,zero,nonfin,subn,ovf) are nowalways_inline,and so are VSET_HEADER's and FPX_FZ_HEADER's non-SSE fallbacks. All are marked
(longshot).a64_v_*became real calls in 46 of 56 chunks (+4.6% game CPU in the firstround below).
-O1the objects keep their sizes and.text(a few dozen bytes differ: the COFF timestamp and a fewoffsets), and the exe's sections are the same sizes.
PROVENANCE.mdnote, with the tree-sha256 updated in the same commit(
check_third_party.py --update a64-kit).nx2/fastfp.py's FASTFP_HEADER, appended to the samea64_fpx.h, had two plainstatichelpers.a64_ff_enabled_is called byA64_FF_ONat every fast float region;a64_ff_checkisA64_FASTFP=checkonly. Both arealways_inlinenow, like the rest of that header.KIT_TREEmoves on with a64-kit's new tree-sha256 (its copy ofemit_functionis unchanged:test_fastfp_override.pycompares them), andtest_fastfp_regions.py's hook follows the enable line.docs/development.md: the switch's row.tests/test_light_passes.py(new, game-free). It fails on main. It checks:LONGSHOT_SPLIT_GIANTS=0, withLONGSHOT_LIGHT_PASSES=0(main's flags for every source), with a lower KB bar,and for kept files;
main()asks it, and that areal clang takes them exactly when it is LLVM 22 or newer;
static inlinehelper ofa64_fpx.hisalways_inline, and every static helper of fastfp's header too (apart from its onenoinlinecold printer).Measurements
Verdict: faster to build, at a small game CPU cost.
15% of a first build's compile: roughly 3 minutes of its 22 at 4 jobs on this PC.
chunks.
+1.38%, adjusted for the PC's other load). fps and frame times didn't change: 58.73 → 58.64 fps, frame time median
16.97 → 16.96 ms.
Why the numbers still hold on main
8a4aa282: they were measured on mainaa95d35f. main's build.py changes since (#30, #35, #37, #356, #540, #577, #660, #857, #673, #1001) don't change a lifted chunk's flags or which chunks compile, and #22's lift key still holds the lifter and fastfp.py (lift_sources), so this PR's header change lifts again once, as Compatibility says. The one change in what the light chunks hold is the fast float regions (#38), whose helpers this PR also makesalways_inline(see Not tested).Hardware: Windows 11 Home, Ryzen 5 5600 (6 cores / 12 threads), 16 GB (RAM at Auto, DOCP off), RX 6700 XT (AMD 26.10.1), Crucial P3 NVMe
Build time.
Scene: the build (no game):
nx2/build.py --standalone --jobs 4withRX_RELEASE=1 A64_HOT_CHUNK=1,RX_MARCHdefault (native: znver3)Method: one lift (main 514591a3's, the same lifter as
aa95d35f). The copy had two edits:a64_fpx.has this PR's lifter writes it, and the 6 lines #573 removed from the lifter taken out ofcode_014.c. Main (aa95d35f) and this PR (6f53b75e: this head's three commits before the rebase ontocefce0d1, without the fastfp lines below) built it in one hold of the PC's job lock, toolchain nightly-130 (clang 23.1.5).Compiler seconds per file are from build.py's
@@filelines. Symbols are from llvm-nm,.textfrom llvm-size, both on the cached objects.How to reproduce:
%LOCALAPPDATA%\LongshotMerge\bold\lightpasses\lp.py A1,B1,A2,B2,L,OFF, thenlpcheck.py(local scripts: the lift is the game's)aa95d35f.textof the 56 objectslongshot.exe.text/ bytesa64_vfpx_mul32_lanes(cold, by design)a64_vfpx_mul32_lanesLONGSHOT_LIGHT_PASSES=0Game speed.
Scene: Hyrule Field from a pinned save, Link standing still, headless, muted, uncapped (
HOS_FPS_MAX=1000, the log says "frame rate uncapped"), 1280x720,RX_VK_PRECOMPILE=0Method: A and B built from one lift copy in one job-lock hold (nightly-189 toolchain,
--jobs 4). A is this branch withLONGSHOT_LIGHT_PASSES=0: its 75 lifted object keys, exe size and.textequal main aa95d35f's build. B is the branch as is: exactly the 56 light chunks differ (50 as split pieces). Two warm-ups, then 11 + 11 interleaved ABBA runs of 240 s, measured over 120-230 s; one renderer DLL for all runs, onlybin\longshot.exeswapped. Every run had its pipelines warm, no translation, no shader or pipeline wait in the window, VRAM 5.7-5.85 GB of 11.47 GB allowed, and no other game, compiler or VM running (watched every 5 s). Medians:How to reproduce:
%LOCALAPPDATA%\LongshotMerge\bold\lightpasses\gab\tools\gab_build.py A,B, thengab_runs.pyandgab_sum.py(local scripts: the lift is the game's)Game-thread CPU, three ways:
The PC was quiet (0.42 cores of other load), so this small cost shows up as real. It fits the ~2.5% larger code. On
this 6-core PC it is off the frame's critical path: fps and frame times didn't move.
Earlier rounds (same flags, the same 56 chunks whole, on main
5e072fc8before the giants were split; a busier PC):always_inlineheader: +4.6%, with 10 of 11 light runs above every main run. The headerfix removed that.
The alternative considered: keep the inliner and turn off only the other module passes (no third_party change).
Compile was only -18% / -6% on code_051 / code_014_1, against -34% / -26% for this (two compiles of each, one at a
time). Rejected.
Flags and settings
One switch added, on by default.
LONGSHOT_LIGHT_PASSES-O1without its module passes;0turns it off0,off,falseornoturns it offLONGSHOT_LIGHT_PASSES_KB-O1Testing
Tested:
python -I -B tests/run_all.py --jobs 4.8a4aa282: 560 passed, 19 failed, 94 skipped. This PR @d7bba514(rebased on it): 561 passed, the same 19 failed,94 skipped (the extra pass is the new test).
test_auto_handheld, test_bug_report_defaults, test_crash_dialog, test_crt_options, test_failed_compile_keeps_objects,
test_guest_imported, test_job_queue, test_linux_preflight, test_make_game_cache, test_missing_nup,
test_pads_after_menu, test_pending_guest_import, test_portable_builder_home, test_portable_builder_startup,
test_run_all_changed, test_tested_configurations, test_vk_occlusion_queries, test_walk_key.
tests/test_light_passes.pypasses here and fails on main (FAIL: nx2/build.py has no light passes).python -I scripts/check_third_party.py: 13 parts as their notes say.static inlinehelperstays a call, an
always_inlineone is inlined, nothing printed), and with an unknown-mllvmoption added the checkrefuses, so the build would fall back to main's flags.
LONGSHOT_LIGHT_PASSES=0(Build time).Not tested:
which LLVM gives for any option it doesn't know (checked above with a made-up one).
a64_ff_enabled_(called at every region) anda64_ff_check(A64_FASTFP=checkonly), arealways_inlinehere like the rest of it, andtests/test_light_passes.pychecks it, so no helper stays a call; the game wasn't timed with fast float regions in it.Must be tested:
few minutes on each, interleaved, at least 3 runs each. Compare the game threads' CPU and the fps, expecting them
within about 1-2% of each other (Test Farm: @Beanstalk steamdeck or a 4-core CPU: compare the game threads' CPU and fps
of main and this PR in Hyrule Field, uncapped)
Risks
What could break: game speed on CPUs with few cores, if the ~3% larger code of the light chunks costs more there
than the +0.75% game CPU measured here. Correctness: none expected (
-opt-disableskips only passes LLVM marksoptional, the same code compiled less; the game-free checks and 22 + 22 game runs found nothing).
Turning it off:
LONGSHOT_LIGHT_PASSES=0(those chunks compile again with main's flags), or revert the commit.Compatibility: the lifter's header changes, so the first build after updating translates the game again (once), and
the light chunks compile again (their flags are in their keys). Saves,
longshot_options.ini, the shader and pipelinecaches, the vk ABI and the builder's tools: nothing changes.
Issues
See #362
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). A deliberate change to a64-kit's lifter header, listed in itsPROVENANCE.mdnote with the tree-sha256 updated in the same commit, as CONTRIBUTING allows.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_light_passes.pyis new; no existing check changed.)🤖 Generated with Claude Code
Tested in game: Windows 11, RX 6700 XT (AMD 26.10.1), Ryzen 5 5600: Hyrule Field from a pinned save, headless and uncapped, 11 + 11 interleaved runs of main's flags against this PR's (built from 6f53b75e, this head before the rebase and the fastfp lines). No crash, no shader or pipeline difference between the two, fps the same (58.73 against 58.64), game-thread CPU +0.75% (load-adjusted). The fast float regions (#38) were not in that lift: see Not tested.
@Beanstalk steamdeck, or any 4-core CPU: build main and this PR, then run Hyrule Field uncapped for a few minutes on each, interleaved, at least 3 runs each. Compare the game threads' CPU and the fps, expecting them within about 1-2% of each other (on this 6-core PC: game-thread CPU +0.75%, fps the same).
@madebyjordan only members of
BigBeanscan start the farm. One of them can approve this request by reacting 👍 to it.@Beanstalk steamdeck, or any 4-core CPU: build main and this PR, then run Hyrule Field uncapped for a few minutes on each, interleaved, at least 3 runs each. Compare the game threads' CPU and the fps, expecting them within about 1-2% of each other (on this 6-core PC: game-thread CPU +0.75%, fps the same).
@madebyjordan approval of
ae701d2recorded. This diff touches sensitive paths, so a second member ofBigBeansmust approve it too.Beanstalk test farm
Commit
d7bba51· tier untrusted · approved by nobody yet · dashboardThis diff touches sensitive paths, so it needs two members of
BigBeans:nx2/build.py,nx2/fastfp.pyA member of
BigBeanscan review this commit and comment@Beanstalkto test it.ae701d2886d7bba51442Reviewed and updated: rebased on main
8a4aa282(clean, no conflicts) and one fix commit,d7bba514.The fix:
-mllvm -opt-disableis new in LLVM 22 (LLVM 20 and 21 don't have it). The README's Linux build without the AppImage uses the system's clang and says an older one still builds, but such a clang would have failed every light chunk ("Unknown command line argument").build.pynow asks the compiler once (light_flags_work: one tiny compile from stdin). If it refuses, the build prints a line saying so and every lifted chunk keeps main's flags.tests/test_light_passes.pychecks the fallback, thatmain()asks, and that a real clang takes the flags exactly when it is LLVM 22 or newer. The docs row says it needs LLVM 22.Checked:
run_all.py --jobs 4on main8a4aa282: 560 passed, 19 failed. On this head: 561 passed, the same 19 failed. None of the 19 reads build.py's flags or the lifter.static inlinehelper stays a call,always_inlineis still inlined, and nothing extra is printed.largestlook right.a64_lift.pyandfastfp.py.The Test Farm approval was for
ae701d2. It needs approving again ford7bba514, and a second BigBeans member still has to approve it.A build-time measurement on Linux, from after the merge. The description lists Linux as untested.
Hardware: Ryzen 9 7900X (24 threads), 30 GB, CachyOS, clang from the dev deps.
Method:
main@43f40b87, built twice as adev_packs.py packon a base of that main.LONGSHOT_LIGHT_PASSES=0first, then the default. Both withLONGSHOT_OBJ_STORE=0, so every lifted chunk compiled.--timing --cpu-only, no game or other build beside it).LONGSHOT_LIGHT_PASSES=0build: 62 lifted chunks without -O1's module passes)compiled inthe build tookdev_packs.py pack)On 24 threads the compile is 43% shorter and the whole pack half as long. That's more than the 21% on 4 jobs in the description. One caveat: this is one pair, with the off build first. The second build may have had a warmer disk cache, though with no object store the compile itself can't reuse objects. The runtime side wasn't measured here.
🤖 Generated with Claude Code