Skip to content

perf(agc): keep full freed-block lists for a thread whose list is empty - #9421

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
JJenkx:windows/host-allocator-kept-lists
Oct 24, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
JJenkx:windows/host-allocator-kept-lists

Conversation

@JJenkx

@JJenkx JJenkx commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Current validation status

Head 87b0ebbcf9 is this PR's one commit on main 83462cc57d. Its tree (48b840958f) is identical to 8dfa950103, the commit measured below, so these results apply to the head unchanged.

Matched trace pair, Windows. Spirit of the Island (PPSA13934), title screen, 125 s per arm, APS5_TRACE_SUMMARY_EVERY=10, steady state from 20 s. Radeon RX 6700 XT, AMD driver 32.0.21045.16010, Windows 11 22621. Only libSceAgcDriver.prx changes between arms, and the arms alternate. Per arm, from tools/trace_digest.py --json of its aps5-summary.jsonl:

arm libSceAgcDriver.prx sha256 steady intervals frame p50, median (ms) presents / 10 s GPU busy / present (ms) busiest worker dropped intervals
main 83462cc57d, run 1 290349533376… 8 111.3 90 53.3 92 % 0
this PR, run 1 F148E07D196F… 10 98.5 102 49.1 91 % 0
main, run 2 290349533376… 10 111.5 90 53.2 92 % 0
this PR, run 2 F148E07D196F… 10 101.1 99 49.8 91 % 0
this PR, run 3 F148E07D196F… 10 100.0 100 49.4 91 % 0

Every arm reports the same VK_EXT_memory_budget device-local heap budget (11235 MiB), with a sampled texture cache budget of 6714–6729 MiB, so the arms are not confounded by a varying heap budget. Frame time is about 10 % lower with this PR (111.4 against 99.9 ms, means of the per-run medians). Most of the gain is in the Driver.Packet phase (about 100 → 90 ms per present). The full comparison, including a sized-delete variant that measured within noise and is not part of this PR, is in this comment. The digests and traces are on disk and available on request. This is one scene on one GPU.

Validation layer, paired. agc_driver_host_allocator, guest_allocator_failures and agc_driver_graphics under VK_LAYER_KHRONOS_validation (ANYPS5_REQUIRE_VULKAN=1, shader cache off), 3 runs per arm on the RX 6700 XT: main 83462cc57d 3/3 each run with 0 VUID lines; this PR 87b0ebbcf9 3/3 each run with 0 VUID lines.

The older measurements and test counts below are historical evidence from 0c6a5bd5938f / a5513aab37e4.

What

On Windows, the driver's operator new and delete (HostAllocator.cpp, from fc25ed9) keep up to 64 freed blocks per 16-byte size class per thread, or 16 blocks above 256 bytes. When blocks are made on one thread and deleted on another, two things happen at once:

  • the deleting thread's list of that class fills, and its later deletes go to the heap;
  • the making thread's list stays empty, and its allocations go to the heap too.

The queue worker and the draw committer do this on every draw.

With this change:

  • A delete that finds its thread's list of the class full hands the whole list to a per-class depot and starts a new list.
  • An allocation that finds its thread's list empty takes a list from the depot before it goes to the heap.
  • Each depot keeps at most eight lists behind an SRW lock, about 5 MiB over all classes. A full list past that still goes to the heap block by block, as before.
  • A kept list is linked through its first block's second word, so every class from 16 bytes up can hold it.

agc_driver_host_allocator gains a case where one thread makes blocks while another deletes them at the same time. It checks:

  • each block's bytes up to its delete;
  • that private bytes stay flat over 12 rounds of 200k blocks.

Why the depot, not deeper lists. I counted cache hits and misses per class, using local counters that are not part of this PR, on the Spirit of the Island title screen. All counts are per 10 s:

build allocations up to 1 KiB missed the cache
main 58M 14.8M
main with lists eight times deeper and classes up to 4 KiB about 58M 13.7M
this change 66M (more frames drawn) 0.44M

On main, the deletes that overflowed to the heap matched the misses class for class. Deeper lists barely changed that, so the misses come from blocks crossing threads, not from bursts deeper than a list.

Where the time went. A steady-state APS5_SAMPLE_WORKER profile of the same screen on main (the 60–140 s difference of two snapshots) has 15.1 % of the queue worker's samples under Allocate and 8.0 % under operator delete, almost all inside ucrtbase/ntdll.

Not a general committer win. tibzejoker measured GTA V (PPSA04264) on an RTX 4090 and i9-13900K: the committer's cost per commit is unchanged with this PR (39.3 → 39.1 µs, one run per tree), while APS5_MIMALLOC=1 lowers it to 34.8 µs. The gain above is measured on Spirit of the Island only.

Not changed.

  • Allocations above 1 KiB, about 3.4M per 10 s on this screen, still go to the heap.
  • The process allocator is unchanged. The APS5_MIMALLOC opt-in measures 97 ms p50 on this screen, against about 108 ms on main and 98.5–100.5 ms with this change.

Tested

Historical validation before the rebase; the current state is under Current validation status above.

Windows 11 Enterprise 10.0.22621, AMD Radeon RX 6700 XT, AMD proprietary driver 26.10.1, Ryzen 9 5950X, WinLibs GCC 15.2 UCRT, Release.

Speed. Spirit of the Island (PPSA13934) 01.000.000, title screen with no input, APS5_TRACE_SECONDS=80:20. Both runtimes used the same shader cache and save. Runs alternated main, change, main, change with no build running. Summary lines of the first pair:

{"commit":"0c6a5bd5938f","dirty":true,"env":{"APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"80:20"},"gpu":"AMD Radeon RX 6700 XT","driver":"AMD proprietary driver 26.10.1 (AMD proprietary shader compiler)","os":"Windows 10.0.22621","cpu":"AMD Ryzen 9 5950X 16-Core Processor","cpu_threads":32,"memory_mib":65457,"title_id":"PPSA13934","title":"Spirit of the Island","content_version":"01.000.000","resolution":"1920x1080","window":{"spec":"seconds 80:20","first_present":1397,"ms":20098.806},"presents":181,"frame_ms":{"p50":110.963,"p90":113.285,"p99":117.065,"max":118.558},"gpu_busy_ms_per_present":52.451,"worker_busy_pct":{"queue worker 0x0":91.516},"top_phases_ms_per_frame":{"Driver.Packet":101.133,"Driver.Packet.draw":85.037,"Driver.Draw":83.365,"Graphics.Draw":69.569,"Driver.Draw.shader_compile_and_link":61.316,"Graphics.Draw.draw_and_resource_release":48.851,"Shader.DrawStage":47.732,"Shader.DrawStage.materialize":27.109},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":3.947,"events_lost":1083461,"totals_full":false},"draw committer":{"events_full_after_s":16.615,"events_lost":55911,"totals_full":false}},"trace":"aps5-trace-0c6a5bd5938f-31300.json.gz"}
{"commit":"a5513aab37e4","dirty":true,"env":{"APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"80:20"},"gpu":"AMD Radeon RX 6700 XT","driver":"AMD proprietary driver 26.10.1 (AMD proprietary shader compiler)","os":"Windows 10.0.22621","cpu":"AMD Ryzen 9 5950X 16-Core Processor","cpu_threads":32,"memory_mib":65457,"title_id":"PPSA13934","title":"Spirit of the Island","content_version":"01.000.000","resolution":"1920x1080","window":{"spec":"seconds 80:20","first_present":1450,"ms":20049.537},"presents":203,"frame_ms":{"p50":98.507,"p90":101.066,"p99":105.849,"max":106.631},"gpu_busy_ms_per_present":48.270,"worker_busy_pct":{"queue worker 0x0":91.550},"top_phases_ms_per_frame":{"Driver.Packet":89.805,"Driver.Packet.draw":73.783,"Driver.Draw":72.177,"Graphics.Draw":68.870,"Driver.Draw.shader_compile_and_link":53.037,"Graphics.Draw.draw_and_resource_release":47.931,"Shader.DrawStage":42.179,"Shader.DrawStage.materialize":22.724},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":4.086,"events_lost":1016952,"totals_full":false},"draw committer":{"events_full_after_s":14.886,"events_lost":90248,"totals_full":false}},"trace":"aps5-trace-a5513aab37e4-546624.json.gz"}

Notes on these lines:

  • dirty is test(agc): align the array window test's texels at run time #8310's test change, applied locally only so that main builds with MinGW (the array-window test's alignas(65536)). It is not part of this PR.
  • The trace event buffers filled before the window ended, but the totals did not (totals_full: false), so the summary lines cover the whole window.
pair arm p50 (ms) p90 (ms) presents in 20 s
1 main 111.0 113.3 181
1 change 98.5 101.1 203
2 main 110.0 112.3 152
2 change 100.5 102.5 199

A second alternated set used APS5_TRACE_SUMMARY_EVERY=10, averaging the 10 s intervals after loading. Private memory was read at 110 s:

run arm p50 (ms) private memory
1 main 108.3 3,566 MiB
2 change 97.9 3,528 MiB
3 main 107.6 3,567 MiB
4 change 99.4 3,583 MiB

No regression on a scene that is not worker-bound. Another Crab's Treasure (PPSA20423), main menu, warm cache, alternated the same way. It is vsync-limited, with the busiest worker 63–71 % busy:

run arm p50 of last 5 intervals (ms) private memory at 125 s
1 main 17.66 5,863 MiB
2 change 17.64 5,807 MiB
3 main 18.21 5,929 MiB
4 change 18.01 5,806 MiB

Tests.

  • agc_driver_host_allocator passes, 3 of 3 runs. The new case reports private bytes of 6.6–7.7 MB after round 4 and 5.9–6.6 MB after round 12.
  • Full ctest with this change: 1868 of 1875 pass. The 7 that fail:
    • patched_libraries, agc_driver_image_array_window_past_layer_limit, agc_driver_sample_order, agc_driver_sample_order_grid_reference, agc_driver_sample_order_recipe_depth_locations and agc_driver_tessellation fail the same way on main 0c6a5bd on this machine.
    • guest_raise_in_system_call timed out under -j 16. Run alone it times out on main too: 3 of 10 runs on main, 2 of 10 with the change.
  • tools/check_conventions.py passes.

Evidence. Traces (aps5-trace-*.json.gz), summary files, trace_digest.py output, sampler profiles, the allocation-count lines and the ctest log: 20261021-host-allocator-kept-lists-PPSA13934.tar.gz (27 MB).

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: AMD Radeon RX 6700 XT, AMD proprietary driver 26.10.1, Windows 11 10.0.22621
  • AI-assisted: yes

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The allocator and cross-thread regression are narrowly scoped, and the description gives unusually useful alternating same-machine measurements, memory observations and baseline-failure accounting. The current evidence is nevertheless for an old base: head a5513aab is 417 commits behind current main 52439815 (merge base 0c6a5bd5). The performance summaries compare that old base with the change, and the repository requires a current-main branch and main/change measurements for performance claims.

Please rebase onto current main, rerun the focused allocator test and relevant regression suite, and repeat the same-scene main/change measurements with traces on that rebased head. Update the full-test failure list if it changes. The hosted product build and test jobs are skipped for this path; the 1,868/1,875 CTest result and GPU/title measurements are author-reported. I did not run the Windows-only allocator test locally because this environment has no matching Windows runtime/build.

@JJenkx

JJenkx commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, @MarcZX10. This PR is rebased onto current main: b79b563 on 4a17c71. It's the same change, with no conflicts. On that base:

Still to do: the same-scene main/change trace pair on this rebased head (Spirit of the Island title screen, APS5_TRACE_SECONDS=80:20, alternating arms) and the GPU-enabled test arms. These are GPU and title runs, which wait for this machine's turn in the launch queue. I'll post the summaries and traces here, and update the failure list if the GPU arms change it.

@JJenkx
JJenkx force-pushed the windows/host-allocator-kept-lists branch from a5513aa to b79b563 Compare October 22, 2026 05:40
@tibzejoker

Copy link
Copy Markdown
Contributor

GTA V (PPSA04264) data for this PR, in the open world from a resumed save. It's the most CPU-bound title I have: the draw committer runs at 83-88 % busy. Machine: RTX 4090 616.92, i9-13900K, Windows 11, WinLibs GCC 15.2.

Base. main 3bbd232 + #9730 + #9181 + #9159 (needed to keep this title alive today) + #9445. The change is the same tree + b79b563. One run per row, APS5_PROFILE_DRAW=1, last 12 windows of 10 s, from the [draw] pipelined lines:

tree committer µs per commit commits / 10 s committer busy
base 39.3 212.5k 83 %
+ this PR 39.1 224.0k 88 %
base + APS5_MIMALLOC=1 34.8 246.2k 86 %

So on this title the depot leaves the cost per commit where it was, within noise. Commits per 10 s follow where the save respawns, so the +5 % there is not a signal. mimalloc, the existing opt-in, cuts the cost per commit by about 11 %.

Why I tested this PR: in the Story prologue on the base tree, APS5_SAMPLE_WORKER put 17 % of queue worker 0's busy samples in HostAllocator::TryAllocate → malloc → the NT heap. Most of those came from draw-stage materialization (PreparedShaderInvocation::Materialize) and DescriptorBindingBuilder::Populate. That is the cross-thread pattern you describe. My guess, not measured: GTA's blocks are often above the 1024-byte LargestCached bound, or the depot's 8 lists drain at GTA's rate (~21k commits per second). An allocation-size histogram on the worker would tell. I can run one if it helps.

For the opt-in debate on #6067 (no Windows frame-time win, worse p99 on paced titles): GTA is a counter-example among committer-bound titles. A 60 s trace window there went from 416 to 518 presents with APS5_MIMALLOC=1, p90 204 → 131 ms. That one window depends on the respawn place, so take the committer cost above as the number.

AI-assisted: yes (Claude Code)

@JJenkx

JJenkx commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

Thank you, this is the counter-measurement the PR needed. On GTA V the depot leaves the committer's cost per commit where it was: 39.3 µs → 39.1 µs, within noise. So the gain it shows on Spirit of the Island (main 111.0/110.0 ms p50 → 98.5/100.5 ms, with misses per 10 s dropping from 14.8M to 0.44M) is specific to that title's pattern and not a general committer win. I've added your result to the description's limitations.

Yes, the size histogram would help. Both of your guesses predict different things:

  • If most of GTA's worker allocations are above LargestCached (1 KiB), the depot can't touch them. The thing to try would then be wider classes, which this PR deliberately doesn't do.
  • If they're within it but the eight lists per class drain, the depot's hit rate would show it. A count of depot takes that found the depot empty would show that directly.

A histogram of request size, per thread, for TryAllocate calls that miss the thread cache would separate the two. If you run it, I'll take the decision from the result: either keep the PR as a Spirit-specific gain, documented as such, or rework it for larger blocks.

The driver's operator new and delete keep up to 64 freed blocks per
16-byte size class per thread (16 above 256 bytes). When blocks are made
on one thread and deleted on another, the deleting thread's list of that
class fills and its further deletes go to the heap, while the making
thread's list stays empty and its allocations go to the heap too. On the
title screen of Spirit of the Island (PPSA13934), with the queue worker
and the draw committer both busy, 14.8M of 58M allocations up to 1 KiB
in 10 s missed the cache, and the deletes that overflowed to the heap
matched the misses class for class. Lists eight times deeper and classes
up to 4 KiB still missed 13.7M times, so the misses are blocks crossing
threads, not bursts deeper than a list.

A delete that finds its thread's list of the class full now hands that
whole list to a per-class depot and starts a new one; an allocation that
finds its thread's list empty takes a list from the depot before going
to the heap. Each depot keeps at most eight lists behind an SRW lock,
about 5 MiB over all classes; a full list past that still goes to the
heap block by block, as before. With this, 0.44M of 66M allocations up
to 1 KiB in 10 s miss on the same screen. A kept list is linked through
its first block's second word, so every class (16 bytes and up) can hold
it.

agc_driver_host_allocator gains a case where one thread makes blocks
that another deletes at the same time, checking their bytes up to the
delete and that private bytes stay flat over 12 rounds of 200k blocks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@JJenkx

JJenkx commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main 83462cc; head is now 87b0ebb. Windows (GCC 15.2.0 UCRT r7, Release): agc_driver_host_allocator and guest_allocator_failures pass in three runs out of three, and conventions pass. With main's HostAllocator.cpp the new cross-thread case passes as well. It checks that blocks keep their bytes and that private memory stays flat when one thread makes blocks and another deletes them. That holds on main too, so it guards correctness and doesn't detect the depot. The speed claim rests only on the trace comparison. A matched Spirit of the Island title-screen comparison on this base is queued on the shared FIFO: four alternating runs, main's libSceAgcDriver against this head's, everything else identical, APS5_TRACE_SUMMARY_EVERY=10. I'll post the summaries when they've run.

@JJenkx
JJenkx force-pushed the windows/host-allocator-kept-lists branch from b79b563 to 87b0ebb Compare October 23, 2026 01:07
@JJenkx

JJenkx commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

New paired A/B on Windows. Same machine, scene and runtime as the earlier depot runs; only libSceAgcDriver.prx is swapped between arms. This replaces the earlier display-blocked attempts, which aborted on surface creation and carry no data.

Setup: Spirit of the Island (PPSA13934), title-screen scene, 125 s per arm, APS5_TRACE_SUMMARY_EVERY=10. Steady state is taken from 20 s on. Radeon RX 6700 XT, AMD proprietary driver 26.10.1, Windows 11 22621, 1920×1080. The arms ran interleaved through the shared FIFO.

Arm libSceAgcDriver.prx Runs Frame p50, median of intervals Presents / 10 s
main 83462cc sha256 29034953… 2 111.3, 111.5 ms 83, 90
this PR 8dfa950103 F148E07D… 3 98.5, 101.1, 100.0 ms 102, 99, 100
this PR + sized delete 3f318cebb0 B3D542C7… 2 99.2, 100.0 ms 101, 100

Frame time is about 10% lower with this PR: 111.4 ms against 99.9 ms, the means of the per-run medians.

tools/trace_digest.py puts the difference in the Driver.Packet phase:

  • That phase falls from about 100 ms to about 90 ms per present.
  • GPU busy per present changes much less, from about 52.5 ms to about 49.5 ms.
  • The busiest worker stays at 91–92 %.

The first main run produced only 8 steady intervals instead of 10. Its medians match the second main run.

The sized-delete variant measures within noise of this PR. It gives no further gain in this scene, so I'm not proposing it.

This is one scene on one GPU. It doesn't contradict @tibzejoker's GTA V result, which showed no change in that title. Traces are on disk and available on request.

@adriadam10 adriadam10 self-assigned this Oct 23, 2026
@adriadam10
adriadam10 dismissed MarcZX10’s stale review October 24, 2026 10:21

Dismissing a stale review: the requested changes were addressed after it (new head and/or updated description with the asked-for runs) and the merge queue blocks on it. Please request changes again if anything is still open.

@adriadam10
adriadam10 merged commit cc277a6 into boykopovar:main Oct 24, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* perf Performance change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants