[pr-performance][memory] Drain retirement queues without walking entries that must wait #274
Loading…
Reference in a new issue
No description provided.
Delete branch "MystifiedSky/Darner:fix/retirement-queue-walk"
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?
Contributor role (optional)
What it changes
darner-late-waithad 752 of its 1,098 samples (4 s window) in the queue walk ofhost::bury(select_ready, inlined).Since
412a0ec(#81), a retirement queue with one out-of-order entry is rotated whole on every drain, with the shard's lock held. Objects wait 64 submissions, so the queues are long. Timelines also showeddarner-relayblocked inretire_resourcebehinddarner-late-wait(about 6 and 9 ms a frame in two of three 4-frame samples).Each shard now keeps its entries by submission number (
BTreeMap<u64, Vec<T>>). A drain visits only the entries it releases. #81's behaviour is kept: an entry behind a later one is still released as soon as its own number has finished.Two differences: released entries now come out ordered by number (arrival order within one) rather than by arrival, and
DARNER_RETIRE_ORDER_DIAGis removed with its four tests, because it counted ready entries hidden behind the head of a queue, which can no longer happen.How it was tested
Tested revision:
d21753c(mainf3840d7plus this change). The game runs used a build of the same code before it was committed; only a code comment differs.Commands and results:
cargo test -p darner-gpu --lib -- bury_tests: 5 passed, also with--features diagnostics.cargo xtask policy --staged: ok. Test failures are listed under the gates.Changes a default: no switch or value changes. The code path changes for everyone.
A/B result: one saved outdoor scene, camera turning at a constant rate by input replay, 60 s warm-up then 120 s measured, old and new alternated (old, new, new, old, old, new), three runs each. Same machine and settings, shaders already cached. Frame rates are rendered frames, not generated ones.
f3840d7Mean frame time grouped by draw count (quartiles), averaged over each side's runs: 33.0 → 31.3, 38.2 → 35.8, 40.1 → 38.2, 45.0 → 40.7 ms. Not every B run beats every A run in every group.
CPU trace, share of the game's samples passing through
host::bury: 2.1% before (772 of 36,179), 0.14% after (79 of 54,507). The "before" trace had procdump attached and the "after" one did not, so treat the comparison as approximate. The A/B runs above had no procdump.Gates run on that revision: the clippy and test runs used the tree of this commit.
cargo clippy --workspace --all-targets --locked -- -D warnings: passed.cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passed.cargo test --workspace --locked(with--no-fail-fast): not clean on this machine. One complete run: 3336 passed, 4 failed, 121 ignored. A second run hung in thewatchtests; its thread stacks showed no thread in the retirement code.f3840d7:sampled_marks_restore_early_depth_only_when_safe_in_pixel_shaders(DXIL validator),shared_scratch_eliminates_flight_settle_end_to_end,ask_once_by_res_splits_reservations_without_refusals.upload::tests::the_pool_is_reserved_in_the_window_and_handed_out_once, was not seen on main. It asserts on a process-wide pool inupload.rs, which this change does not touch.descriptor::tests::records_copied_as_bytes_are_made_at_the_next_syncalso failed once with the change in an earlier run and was not seen on main.f3840d7is flaky here too: itsdarner-gpulib tests failed in 7 of 8 runs with varying tests, and its workspace run did not finish within 7 minutes.Gameplay: RTX 5090 (driver 621.24), Ryzen 9 9950X3D, 64 GB, Windows 11; Series X profile, 4K, DLSS ultra performance, 6x DLSS frame generation, hardware ray tracing. No errors or device removal in the six logs.
Shader wave sizes tested: not applicable.
Hardware dependence: likely general (CPU-side bookkeeping); measured on one machine only.
Coverage gaps:
Checklist
main.docs/asset-policy.md.Checked for overlap
host.rs; none changes the retirement queue.Independent Windows build, gate, and code-read review of
d21753ca9(based onmainf3840d73d). Not run in-game.Environment
x86_64-pc-windows-msvc), MSVC 19.44.35230.Measured results
cargo clippy --workspace --all-targets --locked -- -D warnings): PASScargo clippy --workspace --all-targets --all-features --locked -- -D warnings): PASScargo xtask policy: PASS (asset policy: 555 files ok)cargo test --locked -p darner-gpu --lib host::tests: PASS (123 passed; 0 failed; 3 ignoredin 2.38 s)cargo test --locked -p darner-gpu --lib retire: PASS (13 passed; 0 failedin 0.47 s, includinghost::bury_tests::retirement_queue_moves_objects_without_dropping_them,retirement_queue_releases_up_to_the_threshold_by_number_then_arrival,retirement_queue_matches_partition_for_small_sequences, andbury_drops_retired_objects_asynchronously)Code-read audit
VecDeque<(u64, T)> + orderedwithBTreeMap<u64, Vec<T>>(crates/darner-gpu/src/host.rs:1248-1297) handles non-monotonic retirement numbers cleanly (both multi-thread pushers samplingSTARTED + queuedbefore locking a shard athost.rs:1170-1197andQUEUEDmoving onJob::Present/unfold).select_readyiteratesfirst_entry()and breaks only when*first.key() > finished, so no ready item can be blocked behind a later submission number.select_readymoves everyTviaobjects.into_iter()intodone: &mut Vec<(u64, T)>, keeping allRetired::drop()/ COMReleasecalls outside every shard lock (handed off toBuryPoolor dropped after unlocking athost.rs:1384-1397).(submission_number, arrival_order)breaks no invariants (callers are already sharded acrossRETIRED_SHARDS = 16and dependent pairs are bundled in tuples). Verified zero remaining references to removedDARNER_RETIRE_ORDER_DIAGacross the tree.Verdict: PASS.
AI-assisted: yes (Gemini 4 Neon).
Test report from another PC, in case it helps the review.
I ran into the same thing from the other side: counters of my own showed the retirement queues walking 3.6 to 4.3 million entries a frame while standing still in the open world, nearly all of them entries that had to wait. I had a fix of my own half done when I found this PR, so I dropped it and tested this one instead.
Setup: Ryzen 7 5800X3D (8 cores, 16 threads), RTX 5080, 32 GB, Windows 11.
scripts\play-nvidia.ps1 -NoMenu -Dlss ultraperformance(Series X profile, 2560x1440 output, no ray tracing, no frame generation), standing still in the open world on a daytime save, copied fresh from a backup for each run, 45 s to settle and 120 s measured. Release builds. Tested: this PR's commit (the same diff asd21753c) on my local tree, which is mainf3840d7plus #216 and local changes that are off by default and do not touch the retirement queues. "Base" below is that tree without this PR.darner-late-waitCPU time (ms a second, 2 runs each)So the thread that drains the queues does about 0.35 of a core less work here, and the game ran as before (loaded, stood in the world, no errors in the log).
What I could not show: a frame-time difference. On this PC the frame time in that scene moves by more between runs than the change would make, and the first runs of a new exe are slower here for a reason that has nothing to do with the change (the driver's background threads recompile shaders for the new exe for several runs), so my run-against-run numbers are not usable either way. An in-run A/B behind a switch would settle it; I have not built one for this PR.
Not tested: driving, cutscenes, ray tracing, other hardware.
Code review only (read the diff at
d21753c), nothing built or run. I agree with the earlier audit. A few more checks, all fine:main, so nothing can be freed earlier. Only the order among already-safe objects changes (number, then arrival), and all of them are reference-counted objects whose GPU work has completed.RetirementQueueandselect_readyhave no users outside the bury code.DARNER_RETIRE_ORDER_DIAGhas no README row, menu item or script reference onmain, so removing it leaves nothing dangling.Reviewed with Claude Code (AI-assisted); findings checked by a human before posting.
Testing this now in-game against main (
d21753cvsf3840d7, both release builds with bench-remote).Setup: RTX 5070 Ti 16 GB, driver 621.47, Ryzen 7 7800X3D, 31 GB RAM, Series X profile, 1080p upscaled to 1440p with DLSS Quality, DLSS frame generation 2x, hardware RT on. Automated camera flight over the city (same route and save every run, own home/data folders, both builds on the same warm shader cache since the translator is unchanged).
Plan: 6 alternated runs (main, PR, main, PR, main, PR). I'll post fps / p99 / long frames when it's done.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.