perf(lift): emit the lifted C in several processes on Windows too #2748
Closed
github-sync
wants to merge 2 commits from
github/pr/2748 into main
pull from: github/pr/2748
merge into: MagicBeanDev:main
MagicBeanDev:main
MagicBeanDev:github/pr/2893
MagicBeanDev:github/pr/2890
MagicBeanDev:github/pr/2887
MagicBeanDev:github/pr/2878
MagicBeanDev:github/pr/2875
MagicBeanDev:github/pr/2874
MagicBeanDev:github/pr/2873
MagicBeanDev:github/pr/2871
MagicBeanDev:github/pr/2756
MagicBeanDev:github/pr/2897
MagicBeanDev:github/pr/2896
MagicBeanDev:github/pr/2718
MagicBeanDev:github/pr/2842
MagicBeanDev:github/pr/2691
MagicBeanDev:github/pr/2895
MagicBeanDev:github/pr/2743
MagicBeanDev:github/pr/2765
MagicBeanDev:github/pr/2708
MagicBeanDev:github/pr/2732
MagicBeanDev:github/pr/2755
MagicBeanDev:github/pr/2817
MagicBeanDev:github/pr/2876
MagicBeanDev:release-please--branches--main
MagicBeanDev:release-please--branches--main--release-notes
MagicBeanDev:github/pr/2778
MagicBeanDev:github/pr/2888
MagicBeanDev:github/pr/2866
MagicBeanDev:github/pr/2877
MagicBeanDev:github/pr/2800
MagicBeanDev:github/pr/2829
MagicBeanDev:github/pr/2850
MagicBeanDev:github/pr/2889
MagicBeanDev:github/pr/2882
MagicBeanDev:github/pr/2860
MagicBeanDev:github/pr/2849
MagicBeanDev:github/pr/2886
MagicBeanDev:github/pr/2794
MagicBeanDev:github/pr/2840
MagicBeanDev:github/pr/2830
MagicBeanDev:github/pr/2834
MagicBeanDev:github/pr/2719
MagicBeanDev:github/pr/2742
MagicBeanDev:github/pr/2741
MagicBeanDev:github/pr/2820
MagicBeanDev:github/pr/2771
MagicBeanDev:github/pr/2859
MagicBeanDev:github/pr/2858
MagicBeanDev:github/pr/2823
MagicBeanDev:github/pr/2757
MagicBeanDev:github/pr/2769
MagicBeanDev:github/pr/2844
MagicBeanDev:github/pr/2843
MagicBeanDev:github/pr/2673
MagicBeanDev:github/pr/2855
MagicBeanDev:github/pr/2739
MagicBeanDev:github/pr/2807
MagicBeanDev:github/pr/2851
MagicBeanDev:github/pr/2789
MagicBeanDev:github/pr/2814
MagicBeanDev:github/pr/2818
MagicBeanDev:github/pr/2774
MagicBeanDev:github/pr/2772
MagicBeanDev:github/pr/2750
MagicBeanDev:github/pr/2786
MagicBeanDev:github/pr/2785
MagicBeanDev:github/pr/2782
MagicBeanDev:github/pr/2779
MagicBeanDev:github/pr/2775
MagicBeanDev:github/pr/2706
MagicBeanDev:github/pr/2766
MagicBeanDev:github/pr/2747
MagicBeanDev:github/pr/2759
MagicBeanDev:github/pr/2745
MagicBeanDev:github/pr/2740
MagicBeanDev:github/pr/2733
MagicBeanDev:github/pr/2725
MagicBeanDev:github/pr/2727
MagicBeanDev:github/pr/2728
MagicBeanDev:github/pr/2729
MagicBeanDev:github/pr/2721
MagicBeanDev:github/pr/2722
MagicBeanDev:github/pr/2715
MagicBeanDev:github/pr/2714
MagicBeanDev:github/pr/2707
MagicBeanDev:github/pr/2703
MagicBeanDev:github/pr/2705
MagicBeanDev:github/pr/2697
MagicBeanDev:github/pr/2679
MagicBeanDev:github/pr/2676
MagicBeanDev:github/pr/2669
MagicBeanDev:docs/what-hookshot-connects-to
MagicBeanDev:fix/hdr-encode-test
MagicBeanDev:fix/main-tests
MagicBeanDev:fix/play-cache-files
MagicBeanDev:perf/game-barrier-order
MagicBeanDev:feat/heap-lazy
MagicBeanDev:feat/texture-detail
MagicBeanDev:perf/astc-opaque-bc1
MagicBeanDev:fix/fs-dir-lock
MagicBeanDev:fix/framegen-native-kept
MagicBeanDev:fix/update-no-downgrade
MagicBeanDev:port/k10-gcn-f16-mirrors
MagicBeanDev:fix/framegen-mult-cap
MagicBeanDev:chore/release-as-2.1.1
MagicBeanDev:perf/pcache-load-switch
MagicBeanDev:fix/prepare-progress-log
MagicBeanDev:fix/update-closes-stale-game
MagicBeanDev:fix/hdr-scaled-sampled
MagicBeanDev:perf/first-start-preset
MagicBeanDev:perf/zero-upload
MagicBeanDev:fix/vcore-escape-2s
MagicBeanDev:test/fake-gh-atomic
MagicBeanDev:perf/batch-idle-flush
MagicBeanDev:test/finish-stub-a
MagicBeanDev:chore/record-2.1.0
MagicBeanDev:fix/main-red-tests
MagicBeanDev:fix/test-display-startup-driver-cache
MagicBeanDev:feat/mesh-shader-mode
MagicBeanDev:fix/menu-probes-at-startup
MagicBeanDev:fix/fps-counter-classic
MagicBeanDev:fix/test-log-batch-flake
MagicBeanDev:fix/narrow-screen-hud
MagicBeanDev:ci/prereleases
MagicBeanDev:release/v2.0.15
MagicBeanDev:hotfix/v2.0.15
MagicBeanDev:fix/present-ahead-replay
MagicBeanDev:release/v2.0.13
MagicBeanDev:fix/bracket-paths-2013
MagicBeanDev:fix/hdr-overlays-2013
MagicBeanDev:fix/fps-counter-scale-2013
MagicBeanDev:fix/stick-seen-at-rest
MagicBeanDev:hotfix/menu-fits-screen
MagicBeanDev:fix/f1-always-opens-menu
MagicBeanDev:fix/ini-keep-lines
MagicBeanDev:claude/cranky-pike-7cf247
MagicBeanDev:perf/texture-answer-flat
MagicBeanDev:fix/stamp-test-modules
MagicBeanDev:fix/appimage-fonts
MagicBeanDev:fix/display-awake
MagicBeanDev:release/v2.0.12
MagicBeanDev:fix/discord-windows
MagicBeanDev:rc/v2.0.12-tests
MagicBeanDev:fix/dlss-keep-feature
MagicBeanDev:rc/v2.0.12
MagicBeanDev:button-icons
No reviewers
Labels
Clear labels
accessibility
Barrier affecting people with disabilities
autorelease: pending
autorelease: tagged
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
duplicate
This issue or pull request already exists
enhancement
New feature or request
github_actions
Pull requests that update GitHub Actions code
good first issue
Good for newcomers
help wanted
Extra attention is needed
invalid
This doesn't seem right
question
Further information is requested
testing wanted
wontfix
This will not be worked on
No labels
accessibility
autorelease: pending
autorelease: tagged
bug
dependencies
documentation
duplicate
enhancement
github_actions
good first issue
help wanted
invalid
question
testing wanted
wontfix
Milestone
Clear milestone
No items
No milestone
Assignees
Clear assignees
No assignees
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Hookshot!2748
Loading…
Reference in a new issue
No description provided.
Delete branch "github/pr/2748"
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?
On Windows the lift writes the game's C in one process, because there is no
fork: about 65 s of the lift on a 32-thread PC here, and 145–170 s on the Ryzen 9 3900X of #2636's Phase 0. This is that proposal's item A3: the emit now runs in several new processes on Windows and writes the same files, byte for byte.Who this reaches
Builds that translate the game again. Since #2324 an update with an unchanged lift key skips the lift.
nx2/chunks.pyis one of the key's inputs, so the first build after this lands translates once more.Change
nx2/chunks.py:spawn_emit). Each gets the lifter's small tables once (EMIT_TABLES) and, with each run of 2,000 functions, their bodies; it translates that run's words itself. A3 sketched workers that mapimage.bin; sending the bodies needed no second discovery.a64_lift.Lifter(no subclass, noemit_functionof its own), withnx2/poll.pyinstalled exactly when its counter is passed. Otherwise one process, as before.lift: emit and write (16 processes)or(1 process). #2693's pattern reads both.One more change, for everyone on Windows: the available-memory cap (one process per 2 GB free, from the Steam Deck reports) now applies on Windows too, where free memory was not read before. It is
file_jobs()' cap, so the per-file passes of #2324 are limited by it as well on a PC with little free memory. That cost is not measured, and I can move it to its own PR if you prefer.Measured
i9-13900K (24 cores, 32 threads), 64 GB, NVMe, Windows 11 Home 10.0.26300. The standalone lift (
nx2/lift.py --standalone --write) in its default configuration (polls on,A64_LOCAL_REGSunset, no hot list),main(ba005ca4) and this branch alternated, three runs each:emit and writemain, 1 processIn the game
A full build with the Builder's steps (
nx2/make_game.py --nup, French, shaders not prepared) from this branch plus one unrelated commit (the damaged-texture check opening files several at a time, its own PR): the log sayslift: emit and write (16 processes) in 23.2s. Buildv2.1.0-rc.3-256-gf79aa054, RTX 4090, NVIDIA 621.01, Vulkan 1.4, Windows 11, 5120x1440, upscaler off, frame generation off, 60 fps cap. Kokiri Forest from a save: 52–60 fps, no device lost, no stutter seen, nothing out of place.Testing
tests/test_spawn_emit.py(new, game-free): a reala64_lift.Lifterover a made-up image of 4,500 functions, written bychunks.writewith 1 process and with 3 spawned ones: the same files and counters. It covers:poll.install(),A64_LOCAL_REGS=4, comments on);Liftersubclass (kept in one process).A fallback cannot pass for the spawn: the "worker process stopped" line fails the test.
Teeth: each entry of
EMIT_TABLES, dropped or sent empty, makes it fail (checked by hand).Where it runs: it builds the translator in a temporary folder, so it needs a C++ compiler, as
tests/test_fpx_sticky.pydoes. On the game-free CI (windows-2022 and ubuntu-24.04, Python 3.12) of a private copy of this branch, it passed on both (15.7 s on Windows; 18.2 s and 8.3 s in two Linux runs). Those two Linux runs each had one other failure, a different one each time and outside this change:tests/test_bake_skeleton.pystopped at 600 s on a runner where every check took twice its usual time, thentests/test_linux_saves_move.py(host/hos_main.c) failed once after passing in the first run.python -I -B tests/run_all.pyon Windows: 448 passed, 5 failed.nx2/test_nup_paths.pyneeds the symlink privilege.tests/test_bug_report.pyandtests/test_input_background.pyfail the same way here without this change.nx2/test_nup_verify.pyandtests/test_prepare_at_build.pyfailed once with 32 checks at once and pass alone.Not measured
--no-polls,A64_LOCAL_REGSor a hot list on real data (the test covers the first two on the made-up image).See #2636
See #2324
Assisted-by: Claude Opus 5.5
🤖 Generated with Claude Code
github-sync referenced this pull request2026-11-12 11:35:54 +00:00
Nice change, and the measurements are what I wanted: 66 s down to 21 s for the emit on the i9-13900K (three alternating runs each, so the spread is clear), the 85 gen files SHA-256 identical, and a full Builder-style build plus a play check in the description.
I read the spawn path against Windows semantics and it holds up:
chunksby the path the parent passes, andnx2/lift.pykeeps its work under__main__, so its module-level patches (insn.install()) are all a child re-runs.-Iis passed on to the children bymultiprocessing(checked), so the isolated interpreter the build uses carries over.pool.mapand fails the write, so there is no hang and no half-written output (whole_writemoves files over only at the end).sorted(L.funcs)order andwrite()still decides the boundaries from the texts it gets, so the lift cache and objcache see the same bytes. The.hfiles and the counters are compared in the test too, not only the.cfiles.file_jobs(), soHOOKSHOT_LIFT_JOBSand the memory gate apply, and with one job, a subclassed or patchedLifter, an unexpected poll setup, or fewer than 4000 functions it stays in one process. On Linux and macOS the forked path is untouched (only the log line changes).I ran
python3 -I -B tests/run_all.pyon Linux (the spawn path is exercised there by patching_no_fork) fortest_spawn_emit,test_parallel_emit,test_lift_cache,test_chunk_split,test_chunks_save_folder,test_stale_hot_pieces,test_failure_reason,test_mark_groupsandtest_import_span: all pass.Remarks, none blocking:
poll._installed, a private name ofpoll.py. A small public accessor there would be cleaner, but it is fine as is.file_jobs()is a behaviour change for the per-file passes, which you flag as unmeasured. I'm happy to keep it in this PR: it is the same rule Linux already runs under, and it only bites on a PC with under 32 GB free.Approving on the strength of the numbers and the test coverage.