WIP: perf(build): the runtime's own files built with a play profile of their own (RX_PGO_RT, off unless set) #1986
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!1986
Loading…
Reference in a new issue
No description provided.
Delete branch "siantm/Longshot:perf/build-pgo-rt"
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?
Summary
The hot lifted pieces (
RX_PGO) and the renderer (RX_VK_PGO, the shipped profile) are built with a play profile; theruntime's own files (
host/*.c: the OS layer under every game thread, the input, the sound, the threads' waits) areplain
-O2with none. This addsRX_PGO_RT, off unless set:RX_PGO_RT=gen:host/*.c(and on Linux the executable's fourhost/posixfiles; the renderer's own copy ofwin32_posix.ckeeps its flags) compile counting their branches with atomic adds (-fprofile-update=atomic: everygame thread runs them), and
host/pgo_rt.cis in the executable, so a run withHOS_PGOset to a file name writestheir counters through that name's
.resetand.dumpfiles as anRX_PGO=genrun does (with the hot pieces' toowhen both are set; their adds stay plain, as on
main).RX_PGO_RTset to a merged profile file: they are built with that profile. It is read once and every compile readsa 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. Afterthe compile the build says how many runtime files have counts that apply, and for each file clang noted how many of
its functions (from clang's "of N functions, M mismatched / K without data" notes: a file whose every function is out
of date has none); it stops when no counts apply anywhere. Each object keeps the notes of its compile beside it
(
.rtfit, in the object cache too), and is reused only with them, so a build that reuses objects from one thatstopped early still checks them. The object's stamp is removed before the object or its notes are replaced, so a
build stopped in between leaves no older key that vouches for them.
RX_VK_ONLY) and the release'sthird-party objects never open it.
What changes for the existing counting builds:
host/pgo_rt.c, the writerRX_PGO=gen(and the renderer's copy forRX_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 andtried 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=gentoo) stops on a clang older than 19, whosellvm-profdatareads neitherraw 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.pyand dev.py), anddev.py packs packwith it set builds the game.docs/dev/developing.mdgets "Record the runtime's play profile" (count,runtime, record, merge, build; PowerShell, the queue, files under
work/,RX_PGO=genleft unset since its dump holdsthe game's counters),
docs/dev/reference/build.mdits row, andHOS_PGO's row ingpu/vk/switches.defnames it.Left for a separate change, already on
mainforRX_PGO=gen: on Linux,host/posix/win32_posix.creads the processaffinity in a constructor that the writer's thread, started from another constructor, can race.
From the local branch
exp/x86-asm-sync(RX_PGO_RTof 4eed88f7, with 8c5ecbe9's fix of the profile-key test foldedin: 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 onHOS_PGOwith a.vkfile, a write at exit, clang's own profile runtime); that wouldchange main's
RX_VK_PGO=genandRX_PGO=genrecordings, andRX_VK_PGO_FILEalready records the renderer.Read first:
rt_profile_flags,rt_fit,rt_profile_report,compile_one'srtlines,cache_putand the lines that usert_fl,host_builtandcountinginnx2/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). In the game: an
RX_PGO_RT=genbuild of1cc32eb0recorded a runtime profile in one 90 s market run (HOS_PGOreset once loaded, dumpedbefore the stop,
llvm-profdata merge); the head built with it reported "80 of the 80 runtime files have counts in theprofile", started and played the market in all seven of its runs (Measurements). Game-free checks:
The branch is on
main@9dd41326(unchanged since round 2, so nothing was rebased). Round 1's commits arecafc77c0,72999edf(its tests) and716505fb(its fix); round 2's8d1972d2(failing tests) and1cc32eb0(fix). On top of them comeea90b759(this round's failing test) andd429a14a(its fix, the head). In hidden consoles of their own, through thePC's job queue (fb2-1986r3-1, light, at most two checks at once, 20 minutes a check), with the Vulkan headers
(
RX_CPM):python -I -B tests/test_rt_profile_build.pyatd429a14a: "Ran 14 tests", OK. New this round:build.mainwith a fake compiler, a build withprofile A, then one with profile B stopped where it stamps a runtime object it compiled (the object and its notes
are B's by then), then A again. Every runtime object and its
.rtfitnotes are A's again, and the report finds A'scounts in every runtime file. The fake compiler now writes its object as clang does, to a file of its own moved
into place, so the object the cache shares by a hard link stays the cache's.
counts, the job plans, the clang check, the routes, and the Windows round trip (1,000,000 calls on four threads
after a reset counted exactly, a blocked write, UTF-8 folder and manifest, the profile used).
ea90b759(the test before this round's fix): 1 failure of 14, the new case. Its last build reusesthe two objects B had replaced, by A's old stamp, with B's notes: "77 of the 79 runtime files have counts", "no
counts apply" for those two.
python -I -B tests/test_profile_path_key.pyatd429a14a: "Ran 2 tests", OK.tests/run_all.py --strictatd429a14aover the checks that cutcompile_one/cache_putor read the build'scompile path: 15 passed, 3 failed.
test_compiler_failure,test_third_party_objects,test_mem_gate_leases,test_split_giants,test_build_hash_cache,test_host_depfiles,test_renderer_depfiles,test_link_skip,test_hot_pieces_split,test_header_ext_deps,test_build_long_paths,test_a64_helper_build_flags,test_vk_pgo,test_switches_removedandtest_exclusive_markspass.test_compile_retry_jobs,test_compile_stops_on_exceptionandtest_failed_compile_keeps_objectsfail onmain@9dd41326too, in the samejob (main's own
vk_jobsNameError in their cut ofmain()).run_all.py --strict --changed origin/mainwas not run on the head (it ran in round 2 on an earlier state).Still to test:
for the renderer, which
mainis not (Measurements) (by hand)RX_PGO_RT=genbuild links and writes its counters (host/pgo_rt.c's ELF path, as forRX_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)head with a recorded profile (a later round; by hand)
Measurements
Verdict: in play, no difference shown, no loss seen. In Castle Town's market, six runs a side, the build with a
recorded runtime profile had a median calm-stretch game time of 12.58 ms a frame against
main's 12.68 (0.7 % less), witheach side's runs spread over the other's (12.02 to 12.98 against 12.11 to 13.06). Six runs a side cannot separate a
difference that small from the scene's spread. The switch ships off.
In play: Castle Town's market,
mainagainst this PR with a runtime profile, six runs a sideSetup: Windows 11, i7-9700, RTX 4060, run alone on the PC on 2026-11-22, 18:52 to 19:27 UTC; Castle Town's market (child,
crowded), plain runs of 60 s, frame cap off, output 2560x1440 at the desktop's 2560x1440 at 60 Hz (pinned with
HOS_OUTPUT_RES), programs loaded when the game makes them (RX_VK_LOAD=create); a warm-up run a side, thenM P P M M P P M M P P M, the GPU cooled to 70 °C before each run (at its full 2,745 to 2,760 MHz over every measured
stretch). M =
main@9dd41326. P = this PR withRX_PGO_RTset to a runtime profile: the profile recorded in one 90 smarket run of a counting build of
1cc32eb0(RX_PGO_RT=gen), the build with it reportingd429a14a(1cc32eb0andd429a14ahave the same host code; they differ only innx2/build.py's stamp order and its test). The profile buildreported "80 of the 80 runtime files have counts in the profile", and its executable differs from the same head built
without the profile. Every run's log: no
game window in frontline, no commit-limit line, no frame held unchanged.Calm-stretch game time: the measured 60 s in six 10 s windows, each window whose median game time is more than 20 % above
the run's lowest dropped (a burst), then the median game time of the frames left; blocked: the game thread's wait over
the same frames.
What else differs between the two sides:
main's executable and this head's built without the profile differ only intheir version stamps (30 bytes), so the executable's code differs by the profile alone. The renderer (
longshot_vk.dll)is this head's in P, which adds the
RX_PGO_RTrow to the switch table (gpu/vk/switches.def); the head built withoutthe profile was not run in the game.
9dd41326d429a14a,RX_PGO_RTprofileEach run (run order M1 P2 P3 M4 M5 P6 P7 M8 M9 P10 P11 M12):
Reading: the whole-run game time differs more than the calm-stretch one because two of
main's runs (M1, M8) each hadtwo burst windows; one burst run more or fewer is within what six runs a side give. p99 falls in two groups on both sides
(about 22 or about 45 ms): four of
main's six runs are in the high group against two of this PR's six, a split six runsa side do not show to differ. The fps median follows those runs.
An earlier 3-a-side run (2026-11-22, 03:13 to 03:40 UTC) is withdrawn: one of its runs rendered an 800x600 output after the
desktop changed, and another had the game window brought to the front. Clean build time and size, and Linux, are not
measured.
Game-free checks
Setup: Windows 11, i7-9700, llvm-mingw clang 23.1.5; the checks in Testing, through the PC's job queue, at this round's
test commit and at the fix, in one job
9dd41326with this PR to1cc32eb0and this round's test (ea90b759)d429a14atests/test_rt_profile_build.pytests/test_profile_path_key.pyRisks
Off (unset), every flag and object key is as on
main:rt_flis empty andcountingisRX_PGO=genas before. Set,it changes only developers' builds of
host/*.c: a counting build is slower (never measure it); a profile build hasone in-game comparison so far, not decided (Measurements); keep the switch off until it is decided.
RX_PGO=genandRX_VK_PGO=genrecordings go through the changed writer (atomicclear and copy, the dump written whole before its marker goes), and an
RX_PGO=genbuild now refuses a clang olderthan 19. Players notice nothing: no build they get sets these. A revert is enough.
Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named).main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
tests/that reads changed source is updated, not weakened.Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.Possibly related, for context:
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.
@fixwill do (16)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)nx2/build.py:1300: The generated counters use Clang’s default non-atomic updates. (more on the line)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)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.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.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.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.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)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)docs/dev/developing.md:510: The blanket description of the dump is false with the supported combined counting mode. (more on the line)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)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)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)For the author (2) (a run, a measurement or a decision)
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 at51f5f9da. There are no in-game results, clean build time or size figures, or paired frame-time measurements against6e1521a7.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:
66df764957against6e1521a70a: 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:
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.
@ -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: noprofile 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 theL10 (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 packagainst `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.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.
@ -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 nothingRT_GEN = ["-fprofile-instr-generate", "-mllvm", "-disable-vp=true"]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.
@ -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,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.
@ -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 []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)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)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;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")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.
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 rawmemsetand reading them withfwritewhile 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:
66df764957against6e1521a70a. Read the full patch and the compile, pack-routing, linker and runtime profile-writer paths. No code executed.Pushed
348857bbonmain@6e1521a7, for the reviews of66df7649.1ca31bbdadds the failing tests: build.main's real job plan, and a Windows round trip with four threads, a reset and a blocked write.348857bbis 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.Re #1986 (comment): done in
348857bb, with the failing tests first in1ca31bbd. 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 #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 at1ca31bbd.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 #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 #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 #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 #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 #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 samecountingvalue that decides whether pgo_rt.c is in the plan. Capturing the link is left for a later round.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 #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 #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 #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 #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 #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 #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 #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 #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.
Tested corrected: an earlier run on this PC had no Vulkan headers for the renderer checks (
RX_CPMunset), so the ones it listed as also failing onmainhad compiled nothing on either side. They ran again with the headers at348857bband onmain(queue job fb2-vk-1); the description now gives those results. No check fails at this head alone; nothing in the branch changed.Recommendation: Request changes. At
348857bbagainst6e1521a7, the renderer-only scope, immutable profile snapshot and runtime atomic increment/reset/read paths address my earlier findings. The new profile-use validation can be bypassed on a retry.compile_onerecords warnings only for jobs that actually compile, and successful jobs can stamp/cache objects beforemainreturns for another failed compile. On the retry the cached jobs produce no entries inRT_NOTES;rt_profile_reportthen assumes those files were previously validated. A fully unrelated profile can pass the advertised reject check after a two-pass build, although no completed pass checked its objects. Commit the profile-fit result together with the object or defer reusable cache publication until validation. Include a fixture with an unrelated profile, a late build failure, then a warm retry. Also avoid claiming counts applied to a file merely because it emitted a mismatch warning instead of the unprofiled warning.The Windows fixture is not proof that a gameplay build uses a representative profile. The exact comparison needs matching producer and consumer toolchains, a recording run, and a later build with the merged profile. The ordinary farm plan cannot do that. Keep the opt-in switch off and establish clean build, size and paired gameplay evidence after correcting the report. CI is pending. No PR code ran.
@ -1292,0 +1348,4 @@them). None found: the profile is not this runtime's (another build's, the renderer's, or one from before most of itchanged), so the build stops, and those objects are dropped, so the next build compiles them again. All from the objectcache: they were built with this profile's contents before, and that build said how they matched"""if not RT_NOTES:A cache hit does not prove the later fit check ever ran. If the host objects were stamped and cached before an unrelated compile error returned from main, the warm retry gets no RT_NOTES and can skip rejecting the wrong profile. Tie fit validation to object reuse or defer cache publication until validation completes. Test a wrong profile plus a late unrelated compile failure and warm retry.
348857bbb41cc32eb0b2Pushed
1cc32eb0, onmain@9dd41326, for futondestroyer's second look at348857bb.8d1972d2adds the failing tests: a warm retry after an unrelated failed build, and a report that counts functions. In1cc32eb0each runtime object keeps clang's notes on the profile beside it, in the work folder and in the object cache, and is reused only with them. The report counts functions rather than trusting a missing "unprofiled" warning. Round 1's commits are rebased unchanged (range-diff "=", and context only in one main() hunk). The switch stays off; clean build, size and gameplay evidence are in Still to test with the in-game tester. Testing names which commit each check ran on.Re #1986 (comment): fixed in
1cc32eb0, with the failing test first in8d1972d2. Each runtime object built with a profile now keeps clang's notes from its own compile beside it:Re #1986 (comment): both points are fixed in
1cc32eb0(failing tests in8d1972d2); the branch is rebased onto main @9dd41326. The fit check now travels with the object (the reply on the inline comment has the details), and the warm-retry fixture covers both the folder and the cache. The report no longer counts a file because it lacks the unprofiled warning. It reads clang's "of N functions, M mismatched / K no data" notes, so a file has counts only when some function's apply, and a file whose every function is out of date counts as none. The switch stays off by default. Clean build time, size and paired gameplay evidence (record, merge, then a profile build against main) are pending with the in-game tester and stay in Still to test; this push claims none.Request changes on
1cc32eb0b2828f39ed292563b64b3b7354747a00against9dd41326e71094d8b774459dac5154eb5a3306d9.The stored notes cover the previous same-profile warm retry after an unrelated compile failure, and the report now distinguishes fully mismatched files. The in-folder reuse path still has a cross-profile interruption window.
After a successful profile A build, start a profile B build in the same output folder.
compile_oneoverwrites the runtime object and then writes B's.rtfitwhile A's.sha1still exists. If the build stops before the pending or new key is written, a build with A accepts its old stamp and loads B's notes for B's object. A single affected object can make the retry report the wrong fit or reuse machine code optimized for the wrong profile.Invalidate the old stamp before replacing either payload, or publish the object and its key-bound notes so the prior key cannot certify the replacement. Please cover A → B interrupted after the replacement → A. The clean measurements and paired in-game record, merge and profile-use validation remain open.
Pushed
d429a14a, still onmain@9dd41326(main has not moved, so nothing was rebased), for futondestroyer's third look at1cc32eb0.ea90b759adds the failing test, a build with profile A, then one with B stopped before it stamps a runtime object it replaced, then A again.d429a14aremoves such an object's stamp before the object or its notes are replaced, from the cache or by a compile. Earlier commits are unchanged. The switch stays off. Testing names the queue job and which commit each check ran on.Re #1986 (comment): fixed in
d429a14a, with the failing test first inea90b759. compile_one now removes a runtime object's.sha1stamp before it replaces the object or its.rtfitnotes (from the cache or by a compile), so a build that stops in between leaves no older key that vouches for them, and the next build takes its own key's object from the cache or compiles it. WarmRetry's new case runs A, then B stopped where it stamps the runtime object it compiled, then A again. Atea90b759the last build reused B's two replaced objects and their notes by A's stamp ("77 of the 79 runtime files" with counts), and atd429a14aevery object and its notes are A's again, in the same queue job. The clean build and size measurements and the paired in-game record, merge and profile-use run are with the in-game tester (HostLiftPRs) and have not run yet. The switch stays off.Re #1986 (comment) ("the clean measurements and paired in-game record ... remain open"): the paired in-game run has been done, and Measurements now has it run by run. Castle Town's market, 60 s plain runs on this PC (i7-9700, RTX 4060), run alone, a warm-up a side, then M P P M M P, the GPU cooled before each run:
main9dd41326against this PR withRX_PGO_RTset to a profile recorded from a counting build of1cc32eb0(the same host code as the headd429a14a). Game time a frame, median (range): main 13.10 ms (12.57 to 13.74), with the profile 12.76 (12.52 to 12.98), about 2.6 % less; fps 61.7 (56.1 to 71.3) against 68.4 (66.6 to 72.2); p99 43.6 against 40.4 ms. Reading: not decided, no loss seen: the ranges overlap and there are three runs a side. A rerun of 6 a side is being arranged. Clean build time and size, Linux, and the A → B interrupted → A case of this review's first point are separate: the latter is ind429a14awith its test (ea90b759), described in the update before this one. The switch stays off.Measurements corrected: the sentence that the GPU's clock differed from run to run (915 to 2,760 MHz) was wrong; that median covered the whole log, including loading, menus and the cool-down wait at the idle clock. Over each run's measured 60 s the GPU was at its full clock in every run but P3 (2,415 MHz, waiting for frames); the slowest runs, M3 and M1, ran at full clock with the game thread waiting longer. The figures and the reading are unchanged.
Measurements corrected: two of the six Market runs are left out. P3 rendered an 800x600 output, because this PC's desktop changed to 800x600 at 30 Hz before it started (its lower GPU clock was that); in M3 the game window was brought to the front during the measured minute. With two runs a side (main 12.57 and 13.10 ms of game time a frame, the profile build 12.52 and 12.76) the runs overlap and show no difference either way, so the earlier "about 2.6 % less" no longer stands. A rerun of 6 a side with the output pinned at 2560x1440 is held.
Measurements and Testing: the in-game comparison at six runs a side (Castle Town's market, output pinned at 2560x1440) replaces the withdrawn three-a-side one. Calm-stretch game time 12.58 ms a frame with the runtime profile against 12.68 on
main, inside the spread: no difference shown, no loss seen. What else differs between the two builds is now stated. Still to test now lists the like-for-like pair (this head without and with the profile).Re #1986 (comment) ("the clean measurements and paired in-game record ... remain open"): the paired in-game run is now in Measurements, six interleaved runs a side. Setup: Castle Town's market, 60 s plain runs, cap off, run alone on this PC (i7-9700, RTX 4060), output 2560x1440, the GPU cooled before each run. It compares
main@9dd41326with this PR's head built with a runtime profile, recorded from a counting build of1cc32eb0, which has the same host code. That build reported counts for 80 of the 80 runtime files.main(0.7 % less). Each side's runs spread over the other's (12.02 to 12.98 against 12.11 to 13.06), so no difference is shown, and no loss either.mainruns with burst windows, and a p99 that falls near 22 or 45 ms on both sides: four ofmain's runs in the high group against two of the PR's. Six runs a side do not show that split to differ.main's executable equals this head built without the profile except for its version stamp, so the executable differs by the profile alone. The renderer is the head's on the profile side, with theRX_PGO_RTrow added to the switch table. The head without the profile was not run in the game. Clean build time and size are still not measured.The switch stays off.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.