Skip to content

Compile the generated code with loop-head checkpoints only - #259

Merged
YuutaTsubasa merged 2 commits into
mainfrom
claude/codegen-perf
Oct 23, 2026
Merged

YuutaTsubasa merged 2 commits into
mainfrom
claude/codegen-perf

Conversation

@YuutaTsubasa

Copy link
Copy Markdown
Owner

What

The build now applies scripts/loop_head_checkpoints.py itself. With the new CMake option SFR_LOOP_HEAD_CHECKPOINTS (on by default), each ppc_recomp.*.cpp is converted into <build>/loop-head-checkpoints/ (loop_head_checkpoints.py --file, a custom command per file) and the game compiles those copies. The generated directory is not touched, and output from the current generator, which already checkpoints only loop heads, comes through unchanged.

Why

PR #222 measured that checkpointing only loop heads cuts about 8% from an undrawn race frame on the AYN Thor. Shipping that needed the release's generated directory converted by hand, and that step was never done: up to 0.10.25, releases compiled the shipped code with all 172,524 label checkpoints, and 143,424 of those are at labels that are only reached forwards.

Checked

  • An Android build configured on the shipped directory with this option gives a .text that is byte-identical to a build pointed at a copy converted by hand (43.8 MB, down from 52.6 MB). Windows (clang-cl, D3D12 and Vulkan) races ran to the present limit. A second ninja run with nothing changed does no work.
  • AYN Thor, Dolphin Resort moving race, forced skipping (SFR_RACE_FRAMESKIP=2 SFR_TEST_RACE_DRAW_MS=20), frames 14,000-20,500, three interleaved runs each:
undrawn_ms main cpu_ms undrawn: own work undrawn: blocked
shipped code 7.23 / 7.24 / 6.85 8.87 / 8.77 / 8.68 5.87 / 5.80 / 5.55 1.39 / 1.45 / 1.32
loop heads only 6.70 / 6.86 / 6.73 7.95 / 7.87 / 8.02 4.94 / 4.87 / 4.95 1.77 / 2.01 / 1.76

The main thread's own work in an undrawn frame drops by 14% and its CPU per frame by 9%. The undrawn frame itself drops by 5%: the main thread now gets to its waits for the job workers sooner, and it waits there longer.

  • Windows (i9, D3D12): no change, which is expected because x86-64 doesn't have the hidden checkpoint call.
  • ctest 174/176 (the other two are executables build_tools.ps1 doesn't build); Python 357 OK (11 skipped).

The numbers and a variant that was tried and dropped (packed entry-flag reads) are in docs/performance.md, under "2026-10-23".

Releases need Python 3 at build time while the option is on. They already use it for packaging.

🤖 Generated with Claude Code

The 2026-10-20 work showed that checkpointing only loop heads takes about
8% off an undrawn race frame on the AYN Thor, but releases kept compiling
the shipped generated directory, whose label checkpoints are mostly at
labels reached only forwards (143,424 of 172,524). The build now converts
each ppc_recomp.*.cpp into the build directory through
scripts/loop_head_checkpoints.py --file (CMake option
SFR_LOOP_HEAD_CHECKPOINTS, on by default) and compiles the copies; the
generated directory is untouched and current generator output passes
through unchanged. The result is byte-identical .text to a build pointed
at a hand-made copy.

AYN Thor, forced skipping, three runs each: undrawn_ms 7.11 -> 6.76 ms,
the main thread's own work in an undrawn frame 5.74 -> 4.92 ms, its CPU
per frame 8.77 -> 7.95 ms. Windows unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 23, 2026 08:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@YuutaTsubasa
YuutaTsubasa merged commit ba56553 into main Oct 23, 2026
4 checks passed
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