perf(lift): a Windows lift about a third faster, the same C: fast float checks kept by text, discovery lookups, emit processes started early #1116
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!1116
Loading…
Reference in a new issue
No description provided.
Delete branch "madebyjordan/Longshot:perf/lift-speed"
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 · Needs: Linux, any GPU (a lift compared with main's)
Why
On Windows the launcher's Translate step is now most of an update: today's updates on a Ryzen 5 5600 spent 235-261 s
translating and 20-56 s compiling. Its "emit and write" part took 131-165 s in those builds, where an 11-14 build
took 46 s: since #38 the fast float regions ran a regex 13 times per instruction, for every one of OoT's 13 million. And on Windows the emit's worker
processes waited ~25 s for work the lift's own process did that they never used.
What changed
The lift writes the same C, byte for byte, in about two thirds of the time on Windows. Three commits:
nx2/fastfp.py): the per-instruction checks of #38 are kept by the instruction's text (ff_joins,ff_convs, a cachedfp_is_frame): instruction texts repeat, so 13 million checks become a few hundred thousand.ff_eligiblealso runs its substitution once, not once per word ofFF_BAD.nx2/image.pyEdenImage.lookups/word/in_code,nx2/insn.pyclassify):wordreads a 32-bitview of the image instead of
struct.unpack_from,in_codea flat tuple of ranges, and a word that is a plain op atone pc is remembered as one at every pc (neither classify reads the pc for those). New check
tests/test_lift_lookups.pycompares each with the kit's own answers.nx2/chunks.pyspawn_emit,write,no_texts,fill_fpx,lifter_texts;nx2/lift.py):spawn_emitstarts its processes when called, andchunks.writecalls it first, so they work while the lift'sprocess makes the coverage report (
write(beside=report); its lines and itslift: coveragestep print as before).no_texts: ~15 s and 1-2 GB,used only for
a64_fpx.h's list of FPX shapes). The processes send their runs' shapes back andfill_fpxwritesthe header from them. If a process stops, the texts are made in the lift's process as before (
lifter_texts).Linux (fork) keeps its emit path; it gets the first two commits.
Measurements
Verdict: faster, same output. The Windows lift's median fell from 258 s to 174 s (-33%) at 4 workers on a busy
PC, and the coverage and emit steps together from 150 s to 80 s (-47%). Every run's lifted C is identical to main's
(sha1 of all 102 files in
sa/gen).Hardware: Windows 11, Ryzen 5 5600 (6 cores, 12 threads), 16 GB (about 6 GB free at idle), Crucial P3 NVMe, RX 6700 XT
Scene: none (the lift alone)
Method:
nx2/lift.py --standalone --writeasmake_game.pyruns it (RX_RELEASE=1 A64_HOT_CHUNK=1, the launcher'simage/chunks.txt, the nightly-336 tools' Python 3.14 and llvm-mingw),LONGSHOT_LIFT_JOBS=4so both sides get thesame workers, through
scripts/job_queue.py --mode timing-cpu; 2 interleaved pairs (main, this PR, main, this PR),the median. Other apps were busy (about 47% CPU in the background), so single runs vary by ±25%; the pairs vary together.
How to reproduce:
python -I nx2/lift.py --standalone --write --work NEW_FOLDERwithOOT_EXEFSset, on each side, thencompare
sha1sum NEW_FOLDER/sa/gen/*.8a4aa282464286e5)Baseline: the table's pairs ran on main @
8a4aa282and this PR's commits on it (aaa96fda). Rebased since onto6c8d6e6a, whose only lift change is #1002'salways_inlineina64_fpx.h's helpers (header text, not lift work): onemore pair there, at the default worker count as the launcher runs it, gave main @
6c8d6e6a306.8 s (the gate allowed 2workers; emit and write 206.2 s) and this PR @
464286e5162.2 s (3 workers; emit and write 60.9 s), the lifted C againidentical.
On a quieter PC earlier the same day (not interleaved): main 206 s at 4 workers; this PR 158 s at the default's 3
workers and 126 s at 6. The default count is the Windows memory gate (one per 0.75 GB free): the lift's own process
holds 4.3 GB after discovery, so a 16 GB PC usually gets 3-4.
Flags and settings
None.
Testing
Tested:
sa/gen): identical,on
8a4aa282and again on6c8d6e6a. Italso matches the launcher's own nightly-336 build on this PC (09:33 today): the same size for each of the 92 code
files, and the same sha1 for its 10 other files,
a64_fpx.h(whichfill_fpxnow writes) among them. That buildthen ran about 22 minutes of play (80,813 frames presented, Windows 11, RX 6700 XT, AMD 26.10.1). This PR changes no
byte of the game it builds.
tests/test_spawn_emit.py(one process against three spawned ones over a real lifter, the fallback included)passes with llvm-mingw's clang++. It fails if
fill_fpxis given the wrong shapes (checked by hand).tests/test_lift_lookups.pyfails ifwordreads one word off,in_codetakes a range's end, or the classify cachekeeps a branch (each checked by hand).
6c8d6e6a:test_spawn_emit,test_fastfp_override,test_fastfp_regions,test_lift_lookups,test_lift_workers,test_mark_groups,test_stale_hot_pieces,test_light_passespass.python -I -B tests/run_all.pyon Windows (on8a4aa282): 567 passed, 21 failed, 86 skipped. main @8a4aa282: 566 passed and thesame 21 failed (
test_vk_occlusion_queries,test_crash_dialog,test_linux_preflight,test_job_queue,test_make_game_cache,test_bug_report_defaults,test_run_all_changed,test_tested_configurations,test_portable_builder_home,test_pending_guest_import,test_missing_nup,test_guest_imported,test_walk_key,test_pads_after_menu,test_auto_handheld,test_failed_compile_keeps_objects,test_portable_builder_startup,test_bug_report,test_crt_options,test_audio_output_devices,test_hardware_report). The one extra pass is the new check.Not tested: a lift on Linux or macOS (forked emit processes: their path is unchanged, but the first two commits run
there too), and the lift's time inside a whole
make_game.pybuild (the steps are the same ones).Must be tested:
(
python -I nx2/lift.py --standalone --write --work NEW_FOLDER, or twomake_game.pybuilds), expecting the samesha1 for every file of the work folder's
sa/gen(Test Farm: @Beanstalk linux, the lift on main and on this PR, comparingthe files of sa/gen)
Risks
What could break: the lift, where it would show as a failed lift or a build that differs from main's. On Windows
no_textsswapsa64emit.translateanda64_lift.op_textfor stand-ins while the lifter writes, restored after(also on an error), and
fill_fpxstops the lift ifa64_fpx.hdoesn't begin as expected. The caches only holdanswers that depend on the text alone.
Turning it off: revert the commits (
LONGSHOT_LIFT_JOBS=1also takes the Windows emit off the new path).Compatibility: the lift key changes (translator files changed), so the next update translates the game once, as
for any translator change. The C it writes is the same as before, so the compile finds the same object keys; shader
caches are not touched.
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.🤖 Generated with Claude Code
Tested in game: Windows 11, RX 6700 XT, AMD 26.10.1, Ryzen 5 5600: this PR changes no byte of the game it builds. Its lifted C is identical to main's (sha1 of all 102 files of sa/gen, on
8a4aa282and6c8d6e6a) and to the launcher's nightly-336 build on this PC from 09:33 today (sizes of the 92 code files, sha1 of the other 10, a64_fpx.h among them). That build then ran about 22 minutes of play (80,813 frames presented, logs/longshot_log.txt) with no problem.WIP: perf(lift): a Windows lift about a third faster, the same C: fast float checks kept by text, discovery lookups, emit processes started earlyto perf(lift): a Windows lift about a third faster, the same C: fast float checks kept by text, discovery lookups, emit processes started early@Beanstalk linux: translate the game on main and on this PR (python -I nx2/lift.py --standalone --write --work NEW_FOLDER, a new folder for each, or a make_game.py build of each), then compare the sha1 of every file in each work folder's sa/gen. Expected: every file identical, and the PR's lift no slower than main's (the lift: lines of each log).
@madebyjordan approval of
464286erecorded. This diff touches sensitive paths, so a second member ofBigBeansmust approve it too.Beanstalk test farm
Commit
464286e· tier untrusted · approved by madebyjordan · dashboardThis diff touches sensitive paths, so it needs two members of
BigBeans:nx2/chunks.py,nx2/fastfp.py,nx2/image.py,nx2/insn.py,nx2/lift.pyA member of
BigBeanscan review this commit and comment@Beanstalkto test it.