Skip to content

perf(asset tools): full asset pass ~23 min → ~17 s on Windows (all cores, no cmd.exe, in-process gbagfx/aif2pcm) - #216

Merged
999sian merged 1 commit into
999sian:masterfrom
Strikeborn:perf/asset-tool-parallel
Oct 20, 2026
Merged

999sian merged 1 commit into
999sian:masterfrom
Strikeborn:perf/asset-tool-parallel

Conversation

@Strikeborn

Copy link
Copy Markdown

Result: extract + convert + build together drop from about 23 minutes to about 17 seconds on a 16-core Windows machine (~80×), with byte-identical output. Linux and macOS get the parallel and in-process gains too.

Files: xmake.lua, tools/src/asset_processor/main.cpp, main.h, util.cpp

Cause

Every asset was handled one at a time, and every conversion went through system(). On Windows that's a cmd.exe plus the converter, about 20k process launches per pass, mostly gbagfx. Convert and build also have no up-to-date check (return true; // TODO), so each pass redoes everything.

Change

  1. Worker pool (runJobs): jobs run on all cores (TMC_ASSET_JOBS=N caps it; 1 = the old behaviour). Assets that share any file (raw, editable or built path, e.g. 15 duplicate animation entries) run in order on one thread. Offsets are still recorded afterwards in config order, so generated headers can't change.
  2. Direct launch: check_call starts converters with CreateProcess / posix_spawnp instead of system(). On Windows the child gets the identical command line, so argument parsing is unchanged; elsewhere one level of quotes is stripped, as sh did.
  3. In-process gbagfx and aif2pcm: linked into asset_processor (main renamed to gbagfx_main / aif2pcm_main) and called directly. Neither keeps global state, and both free their buffers; on error they exit, as a failed launch did.
  4. mid2agb / agb2mid (songs) still launch as processes: both keep per-run globals initialised once at startup, so in-process calls would leak settings between songs.
  5. TMC_ASSET_TIMING=1 prints time per asset group. Linux links pthread (needed before glibc 2.34).

Measured (Windows 10, 16 cores, USA)

Step Before (1 thread) All cores + direct launch + in-process gbagfx + in-process aif2pcm
Convert 676 s 262 s 49 s 13 s 8 s
Build 678 s 234 s 43 s 8 s 5 s

Cold extract is 4 s. At every stage, all 21,848 output files were byte-identical to the single-threaded run (SHA-1 per file), and the generated offset headers matched the committed ones.

About 9 s of what's left is the 507 songs. On the test machine, process launches run at ~170/s system-wide no matter how many threads ask (16, 32 and 64 threads all took the same time), so only fewer launches would help, which would mean refactoring the two song tools' globals.

Tested

  • As measured above. Smoke run reaches Entering AgbMain.... Play-tested to the Picori Festival (early game only).
  • Linux (Ubuntu 26.04, GCC 15): all 21,846 asset outputs match Windows (3,753 text files differ only in CRLF vs LF). Convert 3.3 → 0.9 s and build 7.8 → 1.4 s (1 thread → all cores). Not tested on macOS.
  • Ubuntu's packaged xmake 3.0.7 sometimes aborts with corrupted size vs. prev_size after a successful full rebuild. It does this with the original xmake.lua as well, so it's unrelated to this PR.

Developed with assistance from Claude Code (Opus 5.5). I reviewed and tested the changes as described above.

… gbagfx/aif2pcm

Run per-asset work on all cores (TMC_ASSET_JOBS), launch converters with CreateProcess/posix_spawnp instead of system(), and link gbagfx and aif2pcm in-process. Output is byte-identical; a full asset pass drops from ~23 min to ~17 s on Windows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants