WIP: perf(build): the runtime's own files built with a play profile of their own (RX_PGO_RT, off unless set) #1986

Draft
siantm wants to merge 3 commits from siantm/Longshot:perf/build-pgo-rt into main
Contributor

Summary

The hot lifted pieces (RX_PGO) and the renderer (RX_VK_PGO, the shipped profile) are built with a play profile; the
runtime's own files (host/*.c: the OS layer under every game thread, the input, the sound, the threads' waits) are
plain -O2 with none. This adds RX_PGO_RT, off unless set:

  • RX_PGO_RT=gen: host/*.c (and on Linux the executable's four host/posix files; the renderer's own copy of
    win32_posix.c keeps its flags) compile counting their branches with atomic adds (-fprofile-update=atomic: every
    game thread runs them), and host/pgo_rt.c is in the executable, so a run with HOS_PGO set to a file name writes
    their counters through that name's .reset and .dump files as an RX_PGO=gen run does (with the hot pieces' too
    when both are set; their adds stay plain, as on main).
  • RX_PGO_RT set to a merged profile file: they are built with that profile. It is read once and every compile reads
    a copy of its bytes, build/rt_profile/<hash>.profdata; the hash sits beside the flag
    (-DLONGSHOT_RT_PROFILE_SHA1), so the object key follows the profile's contents, not its path or a later merge. After
    the compile the build says how many runtime files found their counts and names those clang noted (out of date,
    missing, none); it stops when none did.
  • The profile is read only when the runtime's files are compiled: the renderer alone (RX_VK_ONLY) and the release's
    third-party objects never open it.

What changes for the existing counting builds: host/pgo_rt.c, the writer RX_PGO=gen (and the renderer's copy for
RX_VK_PGO=gen) already use, now clears and copies the counters word by word with atomic stores and loads, writes
<file>.tmp, checks every write, moves it into place and only then deletes <file>.dump (a failure is said once and
tried again while the marker stays); its marker names have no length limit; a failed allocation or thread start is said
and cleaned up. A counting build (RX_PGO=gen too) stops on a clang older than 19, whose llvm-profdata reads neither
raw format the writer writes. Nothing else changes: no object of a build without these switches, not the lifted code,
not the renderer's objects. It is compile-only (left out of the lift key in make_game.py and dev.py), and dev.py packs pack with it set builds the game. docs/dev/developing.md gets "Record the runtime's play profile" (count,
runtime, record, merge, build; PowerShell, the queue, files under work/, RX_PGO=gen left unset since its dump holds
the game's counters), docs/dev/reference/build.md its row, and HOS_PGO's row in gpu/vk/switches.def names it.
Left for a separate change, already on main for RX_PGO=gen: on Linux, host/posix/win32_posix.c reads the process
affinity in a constructor that the writer's thread, started from another constructor, can race.

From the local branch exp/x86-asm-sync (RX_PGO_RT of 4eed88f7, with 8c5ecbe9's fix of the profile-key test folded
in: the test admitting the RT define; on main that fix has nothing of its own to fix, so it is not a separate PR). Not ported: the branch also gave the renderer this profile and rewrote
host/pgo_rt.c (both modules on HOS_PGO with a .vk file, a write at exit, clang's own profile runtime); that would
change main's RX_VK_PGO=gen and RX_PGO=gen recordings, and RX_VK_PGO_FILE already records the renderer.

Read first: rt_profile_flags, rt_profile_report and the lines that use rt_fl, host_built and counting in
nx2/build.py; host/pgo_rt.c; tests/test_rt_profile_build.py (new).

Testing

Tested: Windows 11, i7-9700, RTX 4060, llvm-mingw clang 23.1.5, Python 3.14.7 (the Builder's); game-free checks
only. No RX_PGO_RT build has run in the game on this PC yet and no runtime profile has been recorded (Still to test).
Each check ran in a hidden console of its own, through the PC's job queue, on head 348857bb (this branch on main @
6e1521a7; main has since gained f1f2dc5b, #1870, which changes another row of gpu/vk/switches.def and merges
cleanly, so these runs are of 348857bb as pushed):

  • python -I -B tests/test_rt_profile_build.py (its compiler: LONGSHOT_MINGW's clang): "Ran 13 tests", OK. The job
    plan from build.main for unset, gen, gen with RX_PGO=gen, a profile (compiled from its copy, the copy unchanged
    when the profile is merged again), a missing profile (stops the game build), the renderer alone and the third-party
    objects with a missing profile (never opened); rt_profile_report; the clang check; the routes. The Windows round
    trip: 1,000,000 calls on four threads after a reset counted exactly, a blocked write that keeps .dump and says so
    and then completes, a UTF-8 folder with the game's manifest, the merged profile used with every count found, and
    clang's out-of-date and unprofiled notes through -Wno-everything.
  • The same file at its own commit 1ca31bbd (before the fix), in the same job: 5 failures and 6 errors. The renderer
    alone stops on the missing profile ("the profile cannot be read"), the counting flags have no atomic adds, the
    profile is compiled from its own path, and the round trip counted 324,706 of the 1,000,000 calls (an earlier run:
    887,320). The errors are the functions the fix adds (rt_profile_report, pgo_writer_supported).
  • python -I -B tests/test_profile_path_key.py: "Ran 2 tests", OK.
  • tests/run_all.py --strict over the other checks that read the build's compile path or switches.def
    (test_a64_helper_build_flags, test_vk_pgo, test_build_long_paths, test_compile_stops_on_exception,
    test_switches_removed, test_cpu_target, test_image_size_guard, test_build_cleanup_scope,
    test_failed_compile_keeps_objects): 8 passed, 1 failed (test_failed_compile_keeps_objects.py), and the same 8
    and 1 on main @ 6e1521a7 in the same job. The full --changed run was not repeated on this head. The renderer checks that the opener's earlier run could not compile (no Vulkan headers: RX_CPM unset), run again with the headers at 348857bb and on main @ 6e1521a7: test_pipeline_states.py passes on both; test_recorder_sync.py, test_present_queue_default.py, test_target_reuse_memory.py and test_vk_occlusion_queries.py fail on main too with the same errors.

Still to test:

  • Windows 11, this PC (i7-9700, RTX 4060): an RX_PGO_RT=gen pack, a run with HOS_PGO set in a heavy place (its
    .reset file once loaded, its .dump file after a few minutes), llvm-profdata merge, then a pack with RX_PGO_RT
    set to the merged profile measured against main (CPU ms a frame, fps), expecting the merge to succeed and the
    profile build to start and play (by hand)
  • Linux: an RX_PGO_RT=gen build links and writes its counters (host/pgo_rt.c's ELF path, as for RX_PGO=gen),
    and the game-free round trip with the POSIX shim added to tests/test_rt_profile_build.py (a later round; by hand)
  • Windows 11, this PC: clean build and link times and the executable's size for the merge base, the head unset and the
    head with a recorded profile (a later round; by hand)

Measurements

Verdict: not measured in play: the switch ships off, and a profile has to be recorded before a build with one can
be compared (Still to test). Only the game-free checks in Testing have run for this PR.

Setup: Windows 11, i7-9700, llvm-mingw clang 23.1.5; the checks in Testing, through the PC's job queue, at the test's
own commit and at the fix, in one job

Before: main @ 6e1521a7 with 66df7649 and the new tests (1ca31bbd) After: this PR @ 348857bb
tests/test_rt_profile_build.py fails (5 failures, 6 errors: the profile opened by the renderer alone, plain adds, 324,706 of 1,000,000 calls counted) passes (13 tests)
tests/test_profile_path_key.py - passes (2 tests)

Risks

Off (unset), every flag and object key is as on main: rt_fl is empty and counting is RX_PGO=gen as before. Set,
it changes only developers' builds of host/*.c: a counting build is slower (never measure it); a profile build is a
build nobody has measured yet. RX_PGO=gen and RX_VK_PGO=gen recordings go through the changed writer (atomic
clear and copy, the dump written whole before its marker goes), and an RX_PGO=gen build now refuses a clang older
than 19. Players notice nothing: no build they get sets these. A revert is enough.

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit.
  • Tested on my own PC, in the game for a change the game runs, as Testing says.
  • mise run test passes (any failure that also fails on main is named).
  • Measured against main, or Measurements says why there is nothing to measure.
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • A check under tests/ that reads changed source is updated, not weakened.
  • Docs updated.
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

Ready to merge

  • Everything in Still to test has run, its results in Tested.
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers").
  • Approved in review, every comment answered.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold.
## Summary The hot lifted pieces (`RX_PGO`) and the renderer (`RX_VK_PGO`, the shipped profile) are built with a play profile; the runtime's own files (`host/*.c`: the OS layer under every game thread, the input, the sound, the threads' waits) are plain `-O2` with none. This adds `RX_PGO_RT`, off unless set: - `RX_PGO_RT=gen`: `host/*.c` (and on Linux the executable's four `host/posix` files; the renderer's own copy of `win32_posix.c` keeps its flags) compile counting their branches with atomic adds (`-fprofile-update=atomic`: every game thread runs them), and `host/pgo_rt.c` is in the executable, so a run with `HOS_PGO` set to a file name writes their counters through that name's `.reset` and `.dump` files as an `RX_PGO=gen` run does (with the hot pieces' too when both are set; their adds stay plain, as on `main`). - `RX_PGO_RT` set to a merged profile file: they are built with that profile. It is read once and every compile reads a copy of its bytes, `build/rt_profile/<hash>.profdata`; the hash sits beside the flag (`-DLONGSHOT_RT_PROFILE_SHA1`), so the object key follows the profile's contents, not its path or a later merge. After the compile the build says how many runtime files found their counts and names those clang noted (out of date, missing, none); it stops when none did. - The profile is read only when the runtime's files are compiled: the renderer alone (`RX_VK_ONLY`) and the release's third-party objects never open it. What changes for the existing counting builds: `host/pgo_rt.c`, the writer `RX_PGO=gen` (and the renderer's copy for `RX_VK_PGO=gen`) already use, now clears and copies the counters word by word with atomic stores and loads, writes `<file>.tmp`, checks every write, moves it into place and only then deletes `<file>.dump` (a failure is said once and tried again while the marker stays); its marker names have no length limit; a failed allocation or thread start is said and cleaned up. A counting build (`RX_PGO=gen` too) stops on a clang older than 19, whose `llvm-profdata` reads neither raw format the writer writes. Nothing else changes: no object of a build without these switches, not the lifted code, not the renderer's objects. It is compile-only (left out of the lift key in `make_game.py` and dev.py), and `dev.py packs pack` with it set builds the game. `docs/dev/developing.md` gets "Record the runtime's play profile" (count, runtime, record, merge, build; PowerShell, the queue, files under `work/`, `RX_PGO=gen` left unset since its dump holds the game's counters), `docs/dev/reference/build.md` its row, and `HOS_PGO`'s row in `gpu/vk/switches.def` names it. Left for a separate change, already on `main` for `RX_PGO=gen`: on Linux, `host/posix/win32_posix.c` reads the process affinity in a constructor that the writer's thread, started from another constructor, can race. From the local branch `exp/x86-asm-sync` (`RX_PGO_RT` of 4eed88f7, with 8c5ecbe9's fix of the profile-key test folded in: the test admitting the RT define; on main that fix has nothing of its own to fix, so it is not a separate PR). Not ported: the branch also gave the renderer this profile and rewrote `host/pgo_rt.c` (both modules on `HOS_PGO` with a `.vk` file, a write at exit, clang's own profile runtime); that would change main's `RX_VK_PGO=gen` and `RX_PGO=gen` recordings, and `RX_VK_PGO_FILE` already records the renderer. Read first: `rt_profile_flags`, `rt_profile_report` and the lines that use `rt_fl`, `host_built` and `counting` in `nx2/build.py`; `host/pgo_rt.c`; `tests/test_rt_profile_build.py` (new). ## Testing **Tested:** Windows 11, i7-9700, RTX 4060, llvm-mingw clang 23.1.5, Python 3.14.7 (the Builder's); game-free checks only. No `RX_PGO_RT` build has run in the game on this PC yet and no runtime profile has been recorded (Still to test). Each check ran in a hidden console of its own, through the PC's job queue, on head 348857bb (this branch on `main` @ 6e1521a7; `main` has since gained f1f2dc5b, #1870, which changes another row of `gpu/vk/switches.def` and merges cleanly, so these runs are of 348857bb as pushed): - `python -I -B tests/test_rt_profile_build.py` (its compiler: LONGSHOT_MINGW's clang): "Ran 13 tests", OK. The job plan from `build.main` for unset, gen, gen with `RX_PGO=gen`, a profile (compiled from its copy, the copy unchanged when the profile is merged again), a missing profile (stops the game build), the renderer alone and the third-party objects with a missing profile (never opened); `rt_profile_report`; the clang check; the routes. The Windows round trip: 1,000,000 calls on four threads after a reset counted exactly, a blocked write that keeps `.dump` and says so and then completes, a UTF-8 folder with the game's manifest, the merged profile used with every count found, and clang's out-of-date and unprofiled notes through `-Wno-everything`. - The same file at its own commit 1ca31bbd (before the fix), in the same job: 5 failures and 6 errors. The renderer alone stops on the missing profile ("the profile cannot be read"), the counting flags have no atomic adds, the profile is compiled from its own path, and the round trip counted 324,706 of the 1,000,000 calls (an earlier run: 887,320). The errors are the functions the fix adds (`rt_profile_report`, `pgo_writer_supported`). - `python -I -B tests/test_profile_path_key.py`: "Ran 2 tests", OK. - `tests/run_all.py --strict` over the other checks that read the build's compile path or `switches.def` (`test_a64_helper_build_flags`, `test_vk_pgo`, `test_build_long_paths`, `test_compile_stops_on_exception`, `test_switches_removed`, `test_cpu_target`, `test_image_size_guard`, `test_build_cleanup_scope`, `test_failed_compile_keeps_objects`): 8 passed, 1 failed (`test_failed_compile_keeps_objects.py`), and the same 8 and 1 on `main` @ 6e1521a7 in the same job. The full `--changed` run was not repeated on this head. The renderer checks that the opener's earlier run could not compile (no Vulkan headers: `RX_CPM` unset), run again with the headers at 348857bb and on `main` @ 6e1521a7: `test_pipeline_states.py` passes on both; `test_recorder_sync.py`, `test_present_queue_default.py`, `test_target_reuse_memory.py` and `test_vk_occlusion_queries.py` fail on `main` too with the same errors. **Still to test:** - Windows 11, this PC (i7-9700, RTX 4060): an `RX_PGO_RT=gen` pack, a run with `HOS_PGO` set in a heavy place (its `.reset` file once loaded, its `.dump` file after a few minutes), `llvm-profdata merge`, then a pack with `RX_PGO_RT` set to the merged profile measured against `main` (CPU ms a frame, fps), expecting the merge to succeed and the profile build to start and play (by hand) - Linux: an `RX_PGO_RT=gen` build links and writes its counters (`host/pgo_rt.c`'s ELF path, as for `RX_PGO=gen`), and the game-free round trip with the POSIX shim added to `tests/test_rt_profile_build.py` (a later round; by hand) - Windows 11, this PC: clean build and link times and the executable's size for the merge base, the head unset and the head with a recorded profile (a later round; by hand) ## Measurements **Verdict:** not measured in play: the switch ships off, and a profile has to be recorded before a build with one can be compared (Still to test). Only the game-free checks in Testing have run for this PR. Setup: Windows 11, i7-9700, llvm-mingw clang 23.1.5; the checks in Testing, through the PC's job queue, at the test's own commit and at the fix, in one job | | Before: main @ 6e1521a7 with 66df7649 and the new tests (1ca31bbd) | After: this PR @ 348857bb | |---|---|---| | `tests/test_rt_profile_build.py` | fails (5 failures, 6 errors: the profile opened by the renderer alone, plain adds, 324,706 of 1,000,000 calls counted) | passes (13 tests) | | `tests/test_profile_path_key.py` | - | passes (2 tests) | ## Risks Off (unset), every flag and object key is as on `main`: `rt_fl` is empty and `counting` is `RX_PGO=gen` as before. Set, it changes only developers' builds of `host/*.c`: a counting build is slower (never measure it); a profile build is a build nobody has measured yet. `RX_PGO=gen` and `RX_VK_PGO=gen` recordings go through the changed writer (atomic clear and copy, the dump written whole before its marker goes), and an `RX_PGO=gen` build now refuses a clang older than 19. Players notice nothing: no build they get sets these. A revert is enough. ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. - [ ] Tested on my own PC, in the game for a change the game runs, as Testing says. - [ ] `mise run test` passes (any failure that also fails on `main` is named). - [ ] Measured against `main`, or Measurements says why there is nothing to measure. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [x] A check under `tests/` that reads changed source is updated, not weakened. - [x] Docs updated. - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold.
perf(build): the runtime's own files built with a play profile of their own (RX_PGO_RT, off unless set)
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 5s
Website / Website on Cloudflare (pull_request_target) Has been skipped
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
Website / Website on Cloudflare (pull_request) Has been cancelled
66df764957
The hot lifted pieces (RX_PGO) and the renderer (RX_VK_PGO) are built with a play profile; the runtime's own files
(host/*.c: the OS layer under every game thread) are plain -O2. RX_PGO_RT=gen compiles them counting their branches
(the same flags as the other two counting builds) with host/pgo_rt.c in the executable, so a run with HOS_PGO=<file>
writes their counters exactly as an RX_PGO=gen run does; RX_PGO_RT=<file> builds them with the merged profile. Its
contents' hash sits beside the flag (-DLONGSHOT_RT_PROFILE_SHA1), so the object key follows the profile and not its
path, as for the other two. Off unless set: no object of a build without it changes.

The renderer keeps main's own profile (RX_VK_PGO and the shipped one); RX_PGO_RT reaches no renderer file. It is
compile-only (make_game.py's and dev.py's COMPILE_ONLY_ENV) and a dev.py pack with it builds the game.

Ported from the local branch exp/x86-asm-sync (4eed88f7's RX_PGO_RT, with 8c5ecbe9's fix of the profile-key test
folded in: the hash built inline beside the flag, the test admitting the RT define). Not ported: that branch applied
the profile to the renderer too and replaced host/pgo_rt.c's writer (both images on HOS_PGO, a .vk file, a write at
exit, clang's profile runtime), which would change main's RX_VK_PGO=gen and RX_PGO=gen recordings; main's writer
and RX_VK_PGO_FILE already do the renderer's.

tests/test_rt_profile_build.py: the flags, the keys, the lift key and the pack route, and on Windows the loop itself
(a file counted beside host/pgo_rt.c, a HOS_PGO dump, llvm-profdata merge, the file built with it with clang's
out-of-date and unprofiled warnings as errors). tests/test_profile_path_key.py knows the third profile.

Assisted-by: Claude Code
Member

Possibly related, for context:

  • PR #1976 WIP: feat(build): the build says how well the play profile fits the hot pieces — Related build-side PGO/profile work; possible build.py overlap
Possibly related, for context: - PR #1976 WIP: feat(build): the build says how well the play profile fits the hot pieces — Related build-side PGO/profile work; possible build.py overlap
BeanBot left a comment

Recommendation: Request changes. A stale runtime profile can stop a renderer-only build, and the new recording path can lose counts when game threads update them concurrently. Fix those paths and verify that a real game build consumes a usable profile before judging the performance gain.

Adds a developer-only build option to record and apply branch profiles for the executable’s host runtime. It reuses the existing writer and object cache, which keeps the build integration small. The cost is a new recording workflow and a recompile of the host jobs whenever the selected profile changes. The default build keeps its existing optimization flags.

@fix will do (16)

  1. L1 nx2/build.py:1816: The builder opens RX_PGO_RT for any standalone invocation, before it filters out jobs the command will never build. (more on the line)
  2. L2 nx2/build.py:1300: The generated counters use Clang’s default non-atomic updates. (more on the line)
  3. L3 nx2/build.py:1316: The cache key hashes one read of the mutable profile, but parallel Clang jobs reopen the original path later. (more on the line)
  4. L4 host/pgo_rt.c:118: The watcher deletes .dump regardless of whether it wrote a complete profile. Renaming the output directory or filling the drive makes the documented completion signal disappear while the profile is absent or truncated. The unchecked allocation at line 84 can also crash the recording process. Check allocation and every write and close, publish the completed file atomically, and acknowledge the marker only after success. Report failures so a developer can retry.
  5. L5 host/pgo_rt.c:108: The watcher silently truncates the marker paths. A valid Windows output path of 255 bytes already overflows the 260-byte buffer once .reset and its terminator are added. The requested marker can be missed, or a different truncated path can be acted on. Construct both paths without truncation and report OS path errors. Add a round trip using a long UTF-8 path and the game’s Windows manifest.
  6. L6 host/pgo_rt.c:54: The new recording mode inherits a writer that emits raw format 10 for every Clang through 22. For example, LLVM 17 uses raw format 8, so its own llvm-profdata cannot merge a dump from this writer. Use the selected compiler’s profiling runtime where available, or reject unsupported recording toolchains at build time and document the supported pair.
  7. L7 (minor) host/pgo_rt.c:130: The reused watcher starts from a constructor and ignores allocation and thread-creation failures. A failed strdup can pass NULL to the worker, and a failed CreateThread leaks the path and leaves no watcher. Successful startup also leaves the handle open. On Linux the worker can reach apply_process_affinity before the separate affinity constructor has finished writing the plain mask. Start after affinity setup or make that setup a thread-safe once operation, and handle path and thread ownership explicitly.
  8. L8 nx2/build.py:1931: The host jobs inherit -Wno-everything, so a readable renderer-only or wholly stale profile can produce a successful runtime build while applying no useful counts. (more on the line)
  9. L9 (minor): The scope says host/*.c only, but the shared job loop also applies the flags to the executable’s four host/posix sources on Linux, including display_sdl.c and win32_posix.c. Name those sources in the description and build reference, or restrict the flags to the documented scope. The renderer’s separate copy of win32_posix.c keeps its old flags.
  10. L10 (minor) docs/dev/developing.md:502: The recipe uses POSIX environment syntax on a feature first tested on Windows, and jumps from making a pack to running it. (more on the line)
  11. L11 (minor) docs/dev/developing.md:510: The blanket description of the dump is false with the supported combined counting mode. (more on the line)
  12. L12 tests/test_rt_profile_build.py:122: The build coverage asserts source strings, while the round trip supplies its own compile and link commands. (more on the line)
  13. L13 tests/test_rt_profile_build.py:162: The only record/merge/use test skips Linux, leaving ELF section retention and the POSIX watcher untested. (more on the line)
  14. L14 tests/test_rt_profile_build.py:148: On Windows, long is 32-bit and the sum over 100,000 calls is about 10.8 billion, so the fixture itself has signed overflow. (more on the line)
  15. L15 (its part an edit can do): Report which runtime functions matched the merged profile so the comparison verifies that the profile was applied.
  16. L16 (its part an edit can do): Use the existing compile and link timings and record the resulting executable size for each variant.

For the author (2) (a run, a measurement or a decision)

  • L15 (minor): The Windows fixture proves a small recording round trip only. Run counting and profile-use game builds on Windows and Linux, including Tier 1 hardware this reaches. Compare the profile-use head with its merge base in matching, interleaved runs after warm-up. Report average FPS, 1% low, median and p99 frame time, and the targeted host CPU time in representative heavy scenes.
  • L16 (minor): There are no clean build time or executable size measurements. Compare the merge base, the head with the switch unset, and the head using the recorded profile with the same compiler, jobs and inputs. Report host compile and executable link time separately from the full build.

Checks: Still running: CI / Conventional Commit title (pull_request), CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request), CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request), CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request), CI / Workflow lint (actionlint) (pull_request), CI / Website build and checks (pull_request), Guide screenshots / Guide images and local UI source review (pull_request), Third-party parts / As their notes say (pull_request), Third-party parts / The same as upstream (pull_request), Website / Website on Cloudflare (pull_request).

More: does it help, other systems, switches, what was read

Does it help: Unproven. The author reports 7 runtime-profile checks and 2 profile-key checks passing on Windows at 66df7649. The earlier comparison used tests copied onto main at 51f5f9da. There are no in-game results, clean build time or size figures, or paired frame-time measurements against 6e1521a7.

Other systems: Lifted code, A64 helpers, third-party audio libraries and renderer-module jobs keep their own flags. The Linux executable also profiles its POSIX window and Win32 shim jobs, whose renderer copies keep their original flags. An enabled profile can alter host-side input, audio, waits, pacing and presentation on every GPU and on Steam Deck. Those paths have no play coverage here. Save formats, shader cache formats and the renderer API are untouched. Renderer-only and prebuilt-object commands can currently fail before the job lists are filtered.

Switches: RX_PGO_RT is build-only and defaults to unset or empty. Opt-in is appropriate for a developer experiment with no shipped profile. The build reference has its row. HOS_PGO still defaults to unset and now also drives the executable’s writer in RX_PGO_RT=gen builds. Its runtime switch-table row is updated, and setting it still disables the crash window.

Reviewed: 66df764957 against 6e1521a70a: Read the full nine-file diff, the new runtime-profile test and the changed profile-key test in full, and the affected sections and callers in build.py, make_game.py, devtools/build.py and devtools/packs.py. Read host/pgo_rt.c, the relevant POSIX shims, toolchain and test-runner paths, AGENTS.md, CONTRIBUTING.md, the Forgejo template and the developer standards. Skimmed adjacent profiling docs, CI setup and the run summaries supplied in the description. The rest of the large build modules was outside the affected paths. No local review checklist or sibling Tooling checkout was present.; nothing run (a code review).

Checked and fine:

  • The intended compile-only classification is consistent with the lift key and dev.py’s diagnostics.
  • Runtime-only profile selection forces a game pack and allows reuse of the base renderer when its inputs are unchanged.
  • Profile paths are normalized out of object keys, while the content digest is retained.
  • The change uses one topic and a Conventional Commit title after the WIP prefix. The commit has an Assisted-by trailer.
  • The patch contains source and documentation only. No game-derived captures, generated files, vendor changes or renderer API changes are present.

Testing: Static review only. The reported Windows checks pass at HEAD. The broader changed-source run was on the earlier rebase and the author reports its 23 failures on that base as well. No comments or reviews contain additional runs. The supplied CI checks are pending.

Overlaps and merge order: None found in the checkout or supplied review data. #1948 already landed in the merge base.


Automated code review by BeanBot (gpt-6.2-sol), on the pull request's opening. Nothing was run; a maintainer decides.

**Recommendation: Request changes.** A stale runtime profile can stop a renderer-only build, and the new recording path can lose counts when game threads update them concurrently. Fix those paths and verify that a real game build consumes a usable profile before judging the performance gain. Adds a developer-only build option to record and apply branch profiles for the executable’s host runtime. It reuses the existing writer and object cache, which keeps the build integration small. The cost is a new recording workflow and a recompile of the host jobs whenever the selected profile changes. The default build keeps its existing optimization flags. **`@fix` will do (16)** 1. **L1** `nx2/build.py:1816`: The builder opens RX_PGO_RT for any standalone invocation, before it filters out jobs the command will never build. (more on the line) 2. **L2** `nx2/build.py:1300`: The generated counters use Clang’s default non-atomic updates. (more on the line) 3. **L3** `nx2/build.py:1316`: The cache key hashes one read of the mutable profile, but parallel Clang jobs reopen the original path later. (more on the line) 4. **L4** `host/pgo_rt.c:118`: The watcher deletes .dump regardless of whether it wrote a complete profile. Renaming the output directory or filling the drive makes the documented completion signal disappear while the profile is absent or truncated. The unchecked allocation at line 84 can also crash the recording process. Check allocation and every write and close, publish the completed file atomically, and acknowledge the marker only after success. Report failures so a developer can retry. 5. **L5** `host/pgo_rt.c:108`: The watcher silently truncates the marker paths. A valid Windows output path of 255 bytes already overflows the 260-byte buffer once .reset and its terminator are added. The requested marker can be missed, or a different truncated path can be acted on. Construct both paths without truncation and report OS path errors. Add a round trip using a long UTF-8 path and the game’s Windows manifest. 6. **L6** `host/pgo_rt.c:54`: The new recording mode inherits a writer that emits raw format 10 for every Clang through 22. For example, LLVM 17 uses raw format 8, so its own llvm-profdata cannot merge a dump from this writer. Use the selected compiler’s profiling runtime where available, or reject unsupported recording toolchains at build time and document the supported pair. 7. **L7** (minor) `host/pgo_rt.c:130`: The reused watcher starts from a constructor and ignores allocation and thread-creation failures. A failed strdup can pass NULL to the worker, and a failed CreateThread leaks the path and leaves no watcher. Successful startup also leaves the handle open. On Linux the worker can reach apply_process_affinity before the separate affinity constructor has finished writing the plain mask. Start after affinity setup or make that setup a thread-safe once operation, and handle path and thread ownership explicitly. 8. **L8** `nx2/build.py:1931`: The host jobs inherit -Wno-everything, so a readable renderer-only or wholly stale profile can produce a successful runtime build while applying no useful counts. (more on the line) 9. **L9** (minor): The scope says host/*.c only, but the shared job loop also applies the flags to the executable’s four host/posix sources on Linux, including display_sdl.c and win32_posix.c. Name those sources in the description and build reference, or restrict the flags to the documented scope. The renderer’s separate copy of win32_posix.c keeps its old flags. 10. **L10** (minor) `docs/dev/developing.md:502`: The recipe uses POSIX environment syntax on a feature first tested on Windows, and jumps from making a pack to running it. (more on the line) 11. **L11** (minor) `docs/dev/developing.md:510`: The blanket description of the dump is false with the supported combined counting mode. (more on the line) 12. **L12** `tests/test_rt_profile_build.py:122`: The build coverage asserts source strings, while the round trip supplies its own compile and link commands. (more on the line) 13. **L13** `tests/test_rt_profile_build.py:162`: The only record/merge/use test skips Linux, leaving ELF section retention and the POSIX watcher untested. (more on the line) 14. **L14** `tests/test_rt_profile_build.py:148`: On Windows, long is 32-bit and the sum over 100,000 calls is about 10.8 billion, so the fixture itself has signed overflow. (more on the line) 15. **L15** (its part an edit can do): Report which runtime functions matched the merged profile so the comparison verifies that the profile was applied. 16. **L16** (its part an edit can do): Use the existing compile and link timings and record the resulting executable size for each variant. **For the author (2)** (a run, a measurement or a decision) - **L15** (minor): The Windows fixture proves a small recording round trip only. Run counting and profile-use game builds on Windows and Linux, including Tier 1 hardware this reaches. Compare the profile-use head with its merge base in matching, interleaved runs after warm-up. Report average FPS, 1% low, median and p99 frame time, and the targeted host CPU time in representative heavy scenes. - **L16** (minor): There are no clean build time or executable size measurements. Compare the merge base, the head with the switch unset, and the head using the recorded profile with the same compiler, jobs and inputs. Report host compile and executable link time separately from the full build. **Checks:** Still running: `CI / Conventional Commit title (pull_request)`, `CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request)`, `CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request)`, `CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request)`, `CI / Workflow lint (actionlint) (pull_request)`, `CI / Website build and checks (pull_request)`, `Guide screenshots / Guide images and local UI source review (pull_request)`, `Third-party parts / As their notes say (pull_request)`, `Third-party parts / The same as upstream (pull_request)`, `Website / Website on Cloudflare (pull_request)`. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Unproven. The author reports 7 runtime-profile checks and 2 profile-key checks passing on Windows at 66df7649. The earlier comparison used tests copied onto main at 51f5f9da. There are no in-game results, clean build time or size figures, or paired frame-time measurements against 6e1521a7. **Other systems:** Lifted code, A64 helpers, third-party audio libraries and renderer-module jobs keep their own flags. The Linux executable also profiles its POSIX window and Win32 shim jobs, whose renderer copies keep their original flags. An enabled profile can alter host-side input, audio, waits, pacing and presentation on every GPU and on Steam Deck. Those paths have no play coverage here. Save formats, shader cache formats and the renderer API are untouched. Renderer-only and prebuilt-object commands can currently fail before the job lists are filtered. **Switches:** RX_PGO_RT is build-only and defaults to unset or empty. Opt-in is appropriate for a developer experiment with no shipped profile. The build reference has its row. HOS_PGO still defaults to unset and now also drives the executable’s writer in RX_PGO_RT=gen builds. Its runtime switch-table row is updated, and setting it still disables the crash window. **Reviewed:** 66df76495791 against 6e1521a70a32: Read the full nine-file diff, the new runtime-profile test and the changed profile-key test in full, and the affected sections and callers in build.py, make_game.py, devtools/build.py and devtools/packs.py. Read host/pgo_rt.c, the relevant POSIX shims, toolchain and test-runner paths, AGENTS.md, CONTRIBUTING.md, the Forgejo template and the developer standards. Skimmed adjacent profiling docs, CI setup and the run summaries supplied in the description. The rest of the large build modules was outside the affected paths. No local review checklist or sibling Tooling checkout was present.; nothing run (a code review). **Checked and fine:** - The intended compile-only classification is consistent with the lift key and dev.py’s diagnostics. - Runtime-only profile selection forces a game pack and allows reuse of the base renderer when its inputs are unchanged. - Profile paths are normalized out of object keys, while the content digest is retained. - The change uses one topic and a Conventional Commit title after the WIP prefix. The commit has an Assisted-by trailer. - The patch contains source and documentation only. No game-derived captures, generated files, vendor changes or renderer API changes are present. **Testing:** Static review only. The reported Windows checks pass at HEAD. The broader changed-source run was on the earlier rebase and the author reports its 23 failures on that base as well. No comments or reviews contain additional runs. The supplied CI checks are pending. **Overlaps and merge order:** None found in the checkout or supplied review data. #1948 already landed in the merge base. </details> --- <sub>Automated code review by BeanBot (gpt-6.2-sol), on the pull request's opening. Nothing was run; a maintainer decides.</sub>
@ -497,0 +499,4 @@
The runtime's own files (`host/*.c`) build at `-O2` with no profile unless `RX_PGO_RT` names one (an experiment: no
profile is shipped, and no gain is measured yet):
1. Build a counting game: `RX_PGO_RT=gen python -I scripts/dev.py packs pack <base> rt-count` (`host/pgo_rt.c` writes the
Member

L10 (minor): The recipe uses POSIX environment syntax on a feature first tested on Windows, and jumps from making a pack to running it. PowerShell cannot run the assignment as written, and starting the base executable records nothing from the pack. Show the PowerShell form, how to assemble the runtime from the pack, and the queued build and run commands. Use quoted absolute paths in a local ignored directory, since pack builds can change checkout and the profile files are not ignored by extension.

**L10** (minor): The recipe uses POSIX environment syntax on a feature first tested on Windows, and jumps from making a pack to running it. PowerShell cannot run the assignment as written, and starting the base executable records nothing from the pack. Show the PowerShell form, how to assemble the runtime from the pack, and the queued build and run commands. Use quoted absolute paths in a local ignored directory, since pack builds can change checkout and the profile files are not ignored by extension.
@ -497,0 +507,4 @@
4. Build with it: `RX_PGO_RT=<rt.profdata> python -I scripts/dev.py packs pack <base> rt-prof`, and measure that pack
against `main`. A function changed since the recording compiles without its counts.
Like the renderer's, it holds function names, shape hashes and branch counts of Longshot's own code, nothing of the game.
Member

L11 (minor): The blanket description of the dump is false with the supported combined counting mode. With RX_PGO=gen and RX_PGO_RT=gen, HOS_PGO writes lifted-game function records as well as host records. State that the runtime-only recipe must leave RX_PGO=gen off, and say explicitly to keep combined captures local.

**L11** (minor): The blanket description of the dump is false with the supported combined counting mode. With RX_PGO=gen and RX_PGO_RT=gen, HOS_PGO writes lifted-game function records as well as host records. State that the runtime-only recipe must leave RX_PGO=gen off, and say explicitly to keep combined captures local.
nx2/build.py Outdated
@ -1292,0 +1297,4 @@
# run's counters); its contents' hash is in the flags as the other two profiles' are, so a new profile compiles these files
# again and the same one does not. Off unless set: every other object, and these without it, as before. The renderer keeps
# its own profile (RX_VK_PGO); host/pgo_rt.c itself counts nothing
RT_GEN = ["-fprofile-instr-generate", "-mllvm", "-disable-vp=true"]
Member

L2: The generated counters use Clang’s default non-atomic updates. Two game threads entering the same host wait or timing routine can lose increments. The watcher also clears live counters with memset and reads them through fwrite while game threads are updating them. Use atomic updates and atomic reset/snapshot operations, or quiesce the counting threads for those operations. Cover the combined RX_PGO=gen mode too, since it shares the same counter section.

**L2**: The generated counters use Clang’s default non-atomic updates. Two game threads entering the same host wait or timing routine can lose increments. The watcher also clears live counters with memset and reads them through fwrite while game threads are updating them. Use atomic updates and atomic reset/snapshot operations, or quiesce the counting threads for those operations. Cover the combined RX_PGO=gen mode too, since it shares the same counter section.
nx2/build.py Outdated
@ -1292,0 +1313,4 @@
with open(prof, "rb") as f:
# (the profile's contents beside its path, as the hot pieces' and the renderer's have them: the object key follows
# the contents, tests/test_profile_path_key.py)
flags = ["-fprofile-instr-use=" + prof,
Member

L3: The cache key hashes one read of the mutable profile, but parallel Clang jobs reopen the original path later. If a developer replaces the profile with a fresh merge during a build, objects compiled against the replacement can be stored under the old digest and reused by later packs. Snapshot the selected bytes to a stable file and compile every job against that snapshot.

**L3**: The cache key hashes one read of the mutable profile, but parallel Clang jobs reopen the original path later. If a developer replaces the profile with a fresh merge during a build, objects compiled against the replacement can be stored under the old digest and reused by later packs. Snapshot the selected bytes to a stable file and compile every job against that snapshot.
nx2/build.py Outdated
@ -1780,1 +1813,4 @@
[os.path.join(rt64, "a64_rt.c")]
# (RX_PGO_RT: the runtime's own files' profile flags; a counting build of them or of the hot pieces has host/pgo_rt.c, the
# counters' writer, in the executable)
rt_fl = rt_profile_flags() if a.standalone else []
Member

L1: The builder opens RX_PGO_RT for any standalone invocation, before it filters out jobs the command will never build. For example, an exported profile path that has been deleted makes dev.py vk or a standalone --third-party-objects build exit. Resolve the profile only when the game host jobs will actually be compiled.

**L1**: The builder opens RX_PGO_RT for any standalone invocation, before it filters out jobs the command will never build. For example, an exported profile path that has been deleted makes dev.py vk or a standalone --third-party-objects build exit. Resolve the profile only when the game host jobs will actually be compiled.
@ -1891,6 +1928,7 @@ def main():
DEPFILE_JOBS[obj] = (host_blob, host_roots, extras)
jobs.append((cc, s, obj,
host_fl + ["-MD", "-I" + os.path.join(OPUS, "include")] +
(rt_fl if os.path.basename(s) != "pgo_rt.c" else []) + # (RX_PGO_RT; the counters' writer counts none)
Member

L8: The host jobs inherit -Wno-everything, so a readable renderer-only or wholly stale profile can produce a successful runtime build while applying no useful counts. The build still prints that it is using the profile. Surface missing and stale profile diagnostics for this mode and require evidence that runtime functions matched, while allowing individual functions to fall back after edits.

**L8**: The host jobs inherit -Wno-everything, so a readable renderer-only or wholly stale profile can produce a successful runtime build while applying no useful counts. The build still prints that it is using the profile. Surface missing and stale profile diagnostics for this mode and require evidence that runtime functions matched, while allowing individual functions to fall back after edits.
@ -0,0 +119,4 @@
def test_the_build_gives_it_to_the_runtimes_files_alone(self):
# (main()'s lines, as they are: the flags only on host/*.c's jobs and never on the counters' writer; the writer in
# the executable, and its link without clang's profile library, whenever something counts)
self.assertIn('rt_fl = rt_profile_flags() if a.standalone else []', BUILD)
Member

L12: The build coverage asserts source strings, while the round trip supplies its own compile and link commands. Both can pass if main drops the writer from the final object list or adds renderer jobs with the wrong flags. Capture the actual jobs and executable link command from build.main and assert the flags and inputs for unset, gen, use, combined counting and renderer-only builds.

**L12**: The build coverage asserts source strings, while the round trip supplies its own compile and link commands. Both can pass if main drops the writer from the final object list or adds renderer jobs with the wrong flags. Capture the actual jobs and executable link command from build.main and assert the flags and inputs for unset, gen, use, combined counting and renderer-only builds.
@ -0,0 +145,4 @@
int main(void) {
const char *f = getenv("HOS_PGO");
char dump[MAX_PATH];
long s = 0;
Member

L14: On Windows, long is 32-bit and the sum over 100,000 calls is about 10.8 billion, so the fixture itself has signed overflow. It also accepts a profile with every count zero, since it checks function names and matching hashes only. Use defined 64-bit arithmetic, run known branch distributions before and after an acknowledged reset, and assert the post-reset counts in the merged profile.

**L14**: On Windows, long is 32-bit and the sum over 100,000 calls is about 10.8 billion, so the fixture itself has signed overflow. It also accepts a profile with every count zero, since it checks function names and matching hashes only. Use defined 64-bit arithmetic, run known branch distributions before and after an acknowledged reset, and assert the post-reset counts in the merged profile.
@ -0,0 +159,4 @@
"""
@unittest.skipUnless(os.name == "nt", "host/pgo_rt.c's Windows writer: the round trip runs on Windows")
Member

L13: The only record/merge/use test skips Linux, leaving ELF section retention and the POSIX watcher untested. The suite also forces --cc clang over CC, and a missing llvm-profdata becomes a successful unittest skip even in the strict suite. Add the ELF round trip with the real POSIX shim and link flags, honor the selected compiler, and make missing required tools visible to strict CI.

**L13**: The only record/merge/use test skips Linux, leaving ELF section retention and the POSIX watcher untested. The suite also forces --cc clang over CC, and a missing llvm-profdata becomes a successful unittest skip even in the strict suite. Add the ELF round trip with the real POSIX shim and link flags, honor the selected compiler, and make missing required tools visible to strict CI.
futondestroyer left a comment

Recommendation: Request changes. The new profile path must be scoped to the jobs that consume it, and the recorder must produce reliable counts before any speed result can be interpreted.

I independently confirm the unrelated-build failure and multithreaded-counter blockers reported at this head. rt_profile_flags() opens the specified profile for standalone renderer-only operations before host jobs are filtered. The test fixture compiles its own commands, so it cannot catch this route. Add an actual job-plan case with a missing runtime profile for a renderer-only build. Atomic Clang increments alone would still leave the watcher clearing counters with a raw memset and reading them with fwrite while game threads run. Define synchronized reset and snapshot behavior as well, then validate the actual writer on Windows and Linux. Ensure dump acknowledgement follows a confirmed complete write. The cache key hashes bytes from a mutable path that parallel compiler jobs subsequently reopen, so give the jobs the same stable snapshot the key hashes.

Does it help: Unproven. The author reported seven runtime-profile and two profile-key checks on Windows. The local compiler/profile round trip is single-threaded, skips Linux, and does not prove that a game build consumes a useful profile. No paired gameplay or clean build time and size result exists, and CI is pending. Keep the developer switch off by default. A normal gameplay farm plan cannot generate, merge, and consume an exact-head runtime profile and then compare the requested build-time switch. Use an explicitly supported multi-stage flow with matching compiler and private inputs once correctness is fixed.

Reviewed: 66df764957 against 6e1521a70a. Read the full patch and the compile, pack-routing, linker and runtime profile-writer paths. No code executed.

**Recommendation: Request changes.** The new profile path must be scoped to the jobs that consume it, and the recorder must produce reliable counts before any speed result can be interpreted. I independently confirm the unrelated-build failure and multithreaded-counter blockers reported at this head. `rt_profile_flags()` opens the specified profile for standalone renderer-only operations before host jobs are filtered. The test fixture compiles its own commands, so it cannot catch this route. Add an actual job-plan case with a missing runtime profile for a renderer-only build. Atomic Clang increments alone would still leave the watcher clearing counters with a raw `memset` and reading them with `fwrite` while game threads run. Define synchronized reset and snapshot behavior as well, then validate the actual writer on Windows and Linux. Ensure dump acknowledgement follows a confirmed complete write. The cache key hashes bytes from a mutable path that parallel compiler jobs subsequently reopen, so give the jobs the same stable snapshot the key hashes. **Does it help:** Unproven. The author reported seven runtime-profile and two profile-key checks on Windows. The local compiler/profile round trip is single-threaded, skips Linux, and does not prove that a game build consumes a useful profile. No paired gameplay or clean build time and size result exists, and CI is pending. Keep the developer switch off by default. A normal gameplay farm plan cannot generate, merge, and consume an exact-head runtime profile and then compare the requested build-time switch. Use an explicitly supported multi-stage flow with matching compiler and private inputs once correctness is fixed. **Reviewed:** 66df764957918e3178a5e9d0879c510ab4752d68 against 6e1521a70a32603ed60a8263e4072625885669b7. Read the full patch and the compile, pack-routing, linker and runtime profile-writer paths. No code executed.
Review of 66df7649 (futondestroyer 62720, BeanBot 62636-62644). The checks that ran the
build's text are replaced by its real job plan (build.main up to the compile, nothing run):
off unless set; RX_PGO_RT=gen counts with atomic adds in every runtime file and never in the
writer, alone and with RX_PGO=gen; a profile is compiled from a copy of its bytes named by
their hash; a missing profile stops a build that compiles the runtime and is never opened by
the renderer alone (RX_VK_ONLY) or the third-party objects. Then rt_profile_report and the
clang a counting build needs.

The Windows round trip now counts 1,000,000 calls on four threads after a reset (none of the
100,000 before it may be in the profile), links the game's manifest and runs under a UTF-8
folder, and checks that a profile that cannot be put in place keeps <file>.dump and says so.
It takes --cc, then CC, then LONGSHOT_MINGW's clang; a clang without llvm-profdata beside it
fails instead of skipping. The fixture's sums are 64-bit.

At this commit the plan, report and round-trip checks fail: the profile is opened by every
standalone build, the adds are plain, .dump goes whether or not the write worked.

Assisted-by: Claude Code
fix(build): RX_PGO_RT only where the runtime is compiled; atomic counts, a whole dump, a stable profile copy
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
Website / Website on Cloudflare (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Successful in 25s
348857bbb4
Review of 66df7649 (futondestroyer 62720, BeanBot 62636-62645):

- The profile is read only when host/*.c are compiled: the renderer alone (RX_VK_ONLY) and the
  release's third-party objects never open it, a missing one included.
- It is read once, and every compile reads a copy of its bytes, build/rt_profile/<hash>.profdata:
  a profile merged again at the same path during a build cannot land under the old hash.
- RX_PGO_RT=gen counts with atomic adds (-fprofile-update=atomic). host/pgo_rt.c clears and
  copies the counters word by word with atomic stores and loads and writes the copy; it writes
  <file>.tmp, checks every write and the close, moves it over <file>, and only then deletes
  <file>.dump. A failure is said once and the write tried again while the marker stays. Marker
  names are built at any length; an allocation or thread start that fails is said and cleaned up,
  and the thread's handle closed.
- A counting build (RX_PGO=gen too: the same writer) stops on a clang older than 19, whose
  llvm-profdata reads neither raw format the writer writes.
- With a profile, clang's notes on it are shown through the files' -Wno-everything
  (-Wprofile-instr-unprofiled/out-of-date/missing), and after the compile the build says how many
  runtime files found their counts and names the rest; it stops when none did, and drops those
  objects so the next build compiles them again.
- developing.md's recipe: PowerShell, the runtime to run, the queue, files under work/, RX_PGO=gen
  left unset (its dump holds the game's counters); build.md and HOS_PGO's row say the same; the
  Linux host/posix files are named.

Assisted-by: Claude Code
Author
Contributor

Pushed 348857bb on main @ 6e1521a7, for the reviews of 66df7649. 1ca31bbd adds the failing tests: build.main's real job plan, and a Windows round trip with four threads, a reset and a blocked write. 348857bb is the fix. The profile is now read only where the runtime's files are compiled, and every compile reads a stable copy named by its hash. Counting uses atomic adds, and host/pgo_rt.c clears and copies the counters atomically and deletes .dump only after the profile is in place whole. Counting builds need clang 19 or newer, a profile build reports which runtime files matched, and the recipe is reworked. Summary, Testing, Measurements and Risks describe this head. The Linux writer run, the in-game measurement, and build times and sizes are still in Still to test.

Pushed 348857bb on `main` @ 6e1521a7, for the reviews of 66df7649. 1ca31bbd adds the failing tests: build.main's real job plan, and a Windows round trip with four threads, a reset and a blocked write. 348857bb is the fix. The profile is now read only where the runtime's files are compiled, and every compile reads a stable copy named by its hash. Counting uses atomic adds, and host/pgo_rt.c clears and copies the counters atomically and deletes .dump only after the profile is in place whole. Counting builds need clang 19 or newer, a profile build reports which runtime files matched, and the recipe is reworked. Summary, Testing, Measurements and Risks describe this head. The Linux writer run, the in-game measurement, and build times and sizes are still in Still to test.
Author
Contributor

Re #1986 (comment): done in 348857bb, with the failing tests first in 1ca31bbd. The profile is read only when host/*.c are compiled, so RX_VK_ONLY and the third-party objects never open it; tests/test_rt_profile_build.py now runs build.main's real job plan, including a renderer-only build with a missing RX_PGO_RT. RX_PGO_RT=gen counts with atomic adds (-fprofile-update=atomic), and host/pgo_rt.c clears and copies the counters word by word with atomic stores and loads and writes the copy. It writes .tmp, checks every write and the close, moves the file into place, and only then deletes .dump; a failure is reported and the marker kept. Every compile reads a copy of the profile named by the hash the key holds (build/rt_profile/.profdata). On Windows the round trip counts exactly 1,000,000 calls made on four threads after a reset, and checks a blocked write. The Linux run of the writer is not covered by this push: it needs a Linux machine and is listed under Still to test. The switch stays off by default, and the measurements are pending.

Re https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1986#issuecomment-62720: done in 348857bb, with the failing tests first in 1ca31bbd. The profile is read only when host/*.c are compiled, so RX_VK_ONLY and the third-party objects never open it; tests/test_rt_profile_build.py now runs build.main's real job plan, including a renderer-only build with a missing RX_PGO_RT. RX_PGO_RT=gen counts with atomic adds (-fprofile-update=atomic), and host/pgo_rt.c clears and copies the counters word by word with atomic stores and loads and writes the copy. It writes <file>.tmp, checks every write and the close, moves the file into place, and only then deletes <file>.dump; a failure is reported and the marker kept. Every compile reads a copy of the profile named by the hash the key holds (build/rt_profile/<hash>.profdata). On Windows the round trip counts exactly 1,000,000 calls made on four threads after a reset, and checks a blocked write. The Linux run of the writer is not covered by this push: it needs a Linux machine and is listed under Still to test. The switch stays off by default, and the measurements are pending.
Author
Contributor

Re #1986 (comment) (L1): fixed in 348857bb. rt_profile_flags runs only when the build compiles the runtime's files (standalone, not RX_VK_ONLY, not --third-party-objects). Plan.test_the_renderer_alone_never_opens_it and test_the_third_party_objects_never_open_it run build.main with a missing profile and check that it plans without opening it; both fail at 1ca31bbd.

Re https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1986#issuecomment-62636 (L1): fixed in 348857bb. rt_profile_flags runs only when the build compiles the runtime's files (standalone, not RX_VK_ONLY, not --third-party-objects). Plan.test_the_renderer_alone_never_opens_it and test_the_third_party_objects_never_open_it run build.main with a missing profile and check that it plans without opening it; both fail at 1ca31bbd.
Author
Contributor

Re #1986 (comment) (L2): fixed in 348857bb. RT_GEN adds -fprofile-update=atomic, and host/pgo_rt.c's reset and dump now clear and copy each counter word with atomic stores and loads, and write the copy, not the live section. The Windows round trip runs 1,000,000 calls on four threads after a reset and requires exactly that count in the merged profile. Combined mode (RX_PGO=gen too) is in the job-plan test; the hot pieces' own adds stay plain as on main, and the description says so.

Re https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1986#issuecomment-62637 (L2): fixed in 348857bb. RT_GEN adds -fprofile-update=atomic, and host/pgo_rt.c's reset and dump now clear and copy each counter word with atomic stores and loads, and write the copy, not the live section. The Windows round trip runs 1,000,000 calls on four threads after a reset and requires exactly that count in the merged profile. Combined mode (RX_PGO=gen too) is in the job-plan test; the hot pieces' own adds stay plain as on main, and the description says so.
Author
Contributor

Re #1986 (comment) (L3): fixed in 348857bb. The profile is read once, and its bytes are copied to build/rt_profile/.profdata, which every runtime compile reads. A new merge at the same path cannot reach objects stored under the old hash. Plan.test_profile_is_read_once_and_compiled_from_a_copy rewrites the profile after planning and checks that the copy is unchanged and the flags name it.

Re https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1986#issuecomment-62638 (L3): fixed in 348857bb. The profile is read once, and its bytes are copied to build/rt_profile/<hash>.profdata, which every runtime compile reads. A new merge at the same path cannot reach objects stored under the old hash. Plan.test_profile_is_read_once_and_compiled_from_a_copy rewrites the profile after planning and checks that the copy is unchanged and the flags name it.
Author
Contributor

Re #1986 (comment) (L8): fixed in 348857bb. With a profile, the runtime jobs add -Wprofile-instr-unprofiled/-out-of-date/-missing after their -Wno-everything (the round trip checks that both notes come through). After the compile the build says how many runtime files found their counts and names the files clang noted. If none found counts, it stops and drops those objects, so a renderer-only or wholly stale profile fails instead of building quietly. Single functions changed since the recording still fall back.

Re https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1986#issuecomment-62639 (L8): fixed in 348857bb. With a profile, the runtime jobs add -Wprofile-instr-unprofiled/-out-of-date/-missing after their -Wno-everything (the round trip checks that both notes come through). After the compile the build says how many runtime files found their counts and names the files clang noted. If none found counts, it stops and drops those objects, so a renderer-only or wholly stale profile fails instead of building quietly. Single functions changed since the recording still fall back.
Author
Contributor

Re #1986 (comment) (L10): fixed in 348857bb. The recipe now gives the PowerShell form, makes a runtime from the pack (dev.py packs rt) and runs that runtime's executable, and runs the build and the recording through the queue. It also keeps the files under the ignored work/ by absolute path.

Re https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1986#issuecomment-62640 (L10): fixed in 348857bb. The recipe now gives the PowerShell form, makes a runtime from the pack (dev.py packs rt) and runs that runtime's executable, and runs the build and the recording through the queue. It also keeps the files under the ignored work/ by absolute path.
Author
Contributor

Re #1986 (comment) (L11): fixed in 348857bb. The recipe says to leave RX_PGO=gen unset, because with it the dump also holds the lifted game's counters, which stay on the developer's PC. The closing sentence now describes only a profile recorded with RX_PGO_RT=gen alone.

Re https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1986#issuecomment-62641 (L11): fixed in 348857bb. The recipe says to leave RX_PGO=gen unset, because with it the dump also holds the lifted game's counters, which stay on the developer's PC. The closing sentence now describes only a profile recorded with RX_PGO_RT=gen alone.
Author
Contributor

Re #1986 (comment) (L12): fixed in 1ca31bbd. The source-string checks are gone; the test captures build.main's real job plan for unset, gen, a profile, combined RX_PGO=gen, renderer-only and third-party-object builds, and asserts each job's flags and whether the writer is in the build. The executable's link command is not captured: it is built after the compile, and its profile options follow the same counting value that decides whether pgo_rt.c is in the plan. Capturing the link is left for a later round.

Re https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1986#issuecomment-62642 (L12): fixed in 1ca31bbd. The source-string checks are gone; the test captures build.main's real job plan for unset, gen, a profile, combined RX_PGO=gen, renderer-only and third-party-object builds, and asserts each job's flags and whether the writer is in the build. The executable's link command is not captured: it is built after the compile, and its profile options follow the same `counting` value that decides whether pgo_rt.c is in the plan. Capturing the link is left for a later round.
Author
Contributor

Re #1986 (comment) (L13): partly fixed in 1ca31bbd. The test no longer forces --cc clang: it takes --cc, then CC, then LONGSHOT_MINGW's clang, then clang on PATH. A clang without llvm-profdata beside it now fails instead of skipping. The ELF round trip with the real POSIX shim is not in this push, because it needs a Linux machine to verify; it is in Still to test and comes in a later round.

Re https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1986#issuecomment-62643 (L13): partly fixed in 1ca31bbd. The test no longer forces --cc clang: it takes --cc, then CC, then LONGSHOT_MINGW's clang, then clang on PATH. A clang without llvm-profdata beside it now fails instead of skipping. The ELF round trip with the real POSIX shim is not in this push, because it needs a Linux machine to verify; it is in Still to test and comes in a later round.
Author
Contributor

Re #1986 (comment) (L14): fixed in 1ca31bbd. The fixture uses int64_t, runs 100,000 calls before an acknowledged reset and 1,000,000 on four threads after it, and requires exactly 1,000,000 as pick's function count in the merged profile, so an all-zero or pre-reset profile fails.

Re https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1986#issuecomment-62644 (L14): fixed in 1ca31bbd. The fixture uses int64_t, runs 100,000 calls before an acknowledged reset and 1,000,000 on four threads after it, and requires exactly 1,000,000 as pick's function count in the merged profile, so an all-zero or pre-reset profile fails.
Author
Contributor

Re #1986 (comment) (L4): fixed in 348857bb. pgo_write checks its allocations, every fwrite and the fclose, writes .tmp, and moves it over . Only then is .dump deleted. A failure is printed to stderr once, the marker stays, and the write is retried every 500 ms. The round trip makes a folder so the move fails, checks that .dump stays and the message is printed, then removes the folder and checks that the profile is written.

Re https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1986#issuecomment-62645 (L4): fixed in 348857bb. pgo_write checks its allocations, every fwrite and the fclose, writes <file>.tmp, and moves it over <file>. Only then is <file>.dump deleted. A failure is printed to stderr once, the marker stays, and the write is retried every 500 ms. The round trip makes <file> a folder so the move fails, checks that .dump stays and the message is printed, then removes the folder and checks that the profile is written.
Author
Contributor

Re #1986 (comment) (L5): fixed in 348857bb. The marker names are built with malloc at any length, and a lookup failure other than "not found" is reported once. The round trip links the game's manifest and runs under a folder with a UTF-8 name. A path over MAX_PATH is not tested: neither the manifest nor this PC opts into Windows long paths, so such a path fails at the OS, which the writer now reports instead of truncating.

Re https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1986#issuecomment-62645 (L5): fixed in 348857bb. The marker names are built with malloc at any length, and a lookup failure other than "not found" is reported once. The round trip links the game's manifest and runs under a folder with a UTF-8 name. A path over MAX_PATH is not tested: neither the manifest nor this PC opts into Windows long paths, so such a path fails at the OS, which the writer now reports instead of truncating.
Author
Contributor

Re #1986 (comment) (L6): fixed in 348857bb. A counting build (RX_PGO_RT=gen, and RX_PGO=gen, which uses the same writer) now stops on a clang older than 19 (build.pgo_writer_supported, from -dumpversion). Raw format 10 came with LLVM 19, and older llvm-profdata reads neither format the writer emits. The build reference says so, and CountingClang checks 17/18/4.2.1 against 19/22/23.

Re https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1986#issuecomment-62645 (L6): fixed in 348857bb. A counting build (RX_PGO_RT=gen, and RX_PGO=gen, which uses the same writer) now stops on a clang older than 19 (build.pgo_writer_supported, from -dumpversion). Raw format 10 came with LLVM 19, and older llvm-profdata reads neither format the writer emits. The build reference says so, and CountingClang checks 17/18/4.2.1 against 19/22/23.
Author
Contributor

Re #1986 (comment) (L7): partly fixed in 348857bb. The constructor checks every allocation and CreateThread, reports a failure and frees what it took, closes the handle on success, and treats an empty HOS_PGO as unset. The Linux affinity race (init_process_affinity's constructor against apply_process_affinity on a thread started by another constructor) is in host/posix/win32_posix.c and is already present on main for RX_PGO=gen. I can't verify a change there on this PC, so it is left for a later round, and the description says so.

Re https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1986#issuecomment-62645 (L7): partly fixed in 348857bb. The constructor checks every allocation and CreateThread, reports a failure and frees what it took, closes the handle on success, and treats an empty HOS_PGO as unset. The Linux affinity race (init_process_affinity's constructor against apply_process_affinity on a thread started by another constructor) is in host/posix/win32_posix.c and is already present on main for RX_PGO=gen. I can't verify a change there on this PC, so it is left for a later round, and the description says so.
Author
Contributor

Re #1986 (comment) (L9): fixed in 348857bb. The build reference, the recipe and the code comment now name the executable's host/posix files on Linux, and the recipe says the renderer's own copy of win32_posix.c keeps its flags.

Re https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1986#issuecomment-62645 (L9): fixed in 348857bb. The build reference, the recipe and the code comment now name the executable's host/posix files on Linux, and the recipe says the renderer's own copy of win32_posix.c keeps its flags.
Author
Contributor

Re #1986 (comment) (L15): the part an edit can do is in 348857bb. After the compile, a profile build reports how many runtime files found their counts and names the files clang noted as out of date or missing; it stops if none matched. The in-game comparison (counting and profile builds on Windows and Linux, profile head against its merge base, interleaved, average fps, 1% low, median and p99) needs a recorded profile and is pending with the in-game tester; it stays in Still to test.

Re https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1986#issuecomment-62645 (L15): the part an edit can do is in 348857bb. After the compile, a profile build reports how many runtime files found their counts and names the files clang noted as out of date or missing; it stops if none matched. The in-game comparison (counting and profile builds on Windows and Linux, profile head against its merge base, interleaved, average fps, 1% low, median and p99) needs a recorded profile and is pending with the in-game tester; it stays in Still to test.
Author
Contributor

Re #1986 (comment) (L16): pending. Clean build and link times and executable sizes for the merge base, the head unset and the head with a recorded profile need full game builds and a recorded profile. They are in Still to test for a later round, and this push claims no figures.

Re https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1986#issuecomment-62645 (L16): pending. Clean build and link times and executable sizes for the merge base, the head unset and the head with a recorded profile need full game builds and a recorded profile. They are in Still to test for a later round, and this push claims no figures.
Author
Contributor

Tested corrected: an earlier run on this PC had no Vulkan headers for the renderer checks (RX_CPM unset), so the ones it listed as also failing on main had compiled nothing on either side. They ran again with the headers at 348857bb and on main (queue job fb2-vk-1); the description now gives those results. No check fails at this head alone; nothing in the branch changed.

Tested corrected: an earlier run on this PC had no Vulkan headers for the renderer checks (`RX_CPM` unset), so the ones it listed as also failing on `main` had compiled nothing on either side. They ran again with the headers at 348857bb and on `main` (queue job fb2-vk-1); the description now gives those results. No check fails at this head alone; nothing in the branch changed.
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
Website / Website on Cloudflare (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Successful in 25s
This pull request is marked as a work in progress.
Some workflows are waiting to be reviewed.
This branch is out-of-date with the base branch
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'perf/build-pgo-rt:siantm-perf/build-pgo-rt'
git switch 'siantm-perf/build-pgo-rt'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
3 participants
Notifications
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/Longshot!1986
No description provided.