Sweep: release trimmed spares off the submitting thread (once-a-second hitch) #3951

Closed
Colej1921 wants to merge 2 commits from upstream-pr/3951 into main
Colej1921 commented 2026-11-30 12:47:20 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Colej1921 on 2026-11-30T12:47:20Z.


What

Fixes a frame hitch that happened about once a second. Under memory pressure, the once-a-second sweep (host.rs sweep()) now releases the spares it trims on a background thread (victory-release). Before, it released them on the submitting thread.

Why

The sweep runs on the submitting thread, before a submission starts. While the PC is under host memory pressure, which can happen even on a 32 GB PC (1–2 GB free while the title runs), the sweep trims three kinds of spare:

  • scratch chunks
  • copy sources
  • send memory

Releasing those D3D12 buffers took 22–45 ms every second:

  • 7–24 ms releasing scratch chunks (trim_spare_chunks)
  • 11–15 ms releasing send memory (send::trim)

As a result, one frame came in late in nearly every second, even at a steady 30 fps. I found this with per-step timing of the sweep (not included in this PR).

No list names what a trim lets go of: a list holds what it records until it is reset. So only the release itself is left, and D3D12 objects are free-threaded. The release thread holds none of our locks.

Measured

Rig: Ryzen 7 7700X, RTX 4070 SUPER, 32 GB, Series S profile, DLSS frame generation 2x, 30 fps cap. Two 90-second walks with the game focused, on the same build, with only VICTORY_RELEASE_APART different:

VICTORY_RELEASE_APART on (default) =0 (as before)
seconds with a frame over 66 ms 4 / 88 26 / 88
seconds with a frame over 100 ms 0 1
sweeps of 20 ms or more 3 85

A standing-still pair at the same spot, uncapped: seconds whose longest frame was more than 40 ms above that second's median went from 21/60 to 1/60.

Notes

  • VICTORY_RELEASE_APART=0 restores the old behaviour.
  • Only the three sweep-time trims use it: trim_spare_uploads, trim_spare_chunks and send::trim. Other drops are unchanged.
  • Tests: cargo test -p victory-gpu --lib gives 920 passed, 2 failed. Both failures predate this PR:
    • shader_cache::tests::every_switch_of_the_translator_is_in_the_key fails on main without this change.
    • card_steps::places_written_after_sending_are_learned is flaky and passes when run alone.
  • Clippy: cargo clippy -p victory-gpu --all-targets -- -D warnings reports the same 4 errors as main, none of them new.

🤖 Generated with Claude Code

https://claude.ai/code/session_01TqPhfCMSaeRyntpNrQy31k

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5565569776 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3951). Originally posted by [Colej1921](https://github.com/Colej1921) on 2026-11-30T12:47:20Z. --- ## What Fixes a frame hitch that happened about once a second. Under memory pressure, the once-a-second sweep (`host.rs` `sweep()`) now releases the spares it trims on a background thread (`victory-release`). Before, it released them on the submitting thread. ## Why The sweep runs on the submitting thread, before a submission starts. While the PC is under host memory pressure, which can happen even on a 32 GB PC (1–2 GB free while the title runs), the sweep trims three kinds of spare: - scratch chunks - copy sources - send memory Releasing those D3D12 buffers took **22–45 ms every second**: - 7–24 ms releasing scratch chunks (`trim_spare_chunks`) - 11–15 ms releasing send memory (`send::trim`) As a result, one frame came in late in nearly every second, even at a steady 30 fps. I found this with per-step timing of the sweep (not included in this PR). No list names what a trim lets go of: a list holds what it records until it is reset. So only the release itself is left, and D3D12 objects are free-threaded. The release thread holds none of our locks. ## Measured Rig: Ryzen 7 7700X, RTX 4070 SUPER, 32 GB, Series S profile, DLSS frame generation 2x, 30 fps cap. Two 90-second walks with the game focused, on the same build, with only `VICTORY_RELEASE_APART` different: | | `VICTORY_RELEASE_APART` on (default) | `=0` (as before) | |---|---|---| | seconds with a frame over 66 ms | **4 / 88** | 26 / 88 | | seconds with a frame over 100 ms | 0 | 1 | | sweeps of 20 ms or more | **3** | 85 | A standing-still pair at the same spot, uncapped: seconds whose longest frame was more than 40 ms above that second's median went from 21/60 to 1/60. ## Notes - `VICTORY_RELEASE_APART=0` restores the old behaviour. - Only the three sweep-time trims use it: `trim_spare_uploads`, `trim_spare_chunks` and `send::trim`. Other drops are unchanged. - **Tests:** `cargo test -p victory-gpu --lib` gives 920 passed, 2 failed. Both failures predate this PR: - `shader_cache::tests::every_switch_of_the_translator_is_in_the_key` fails on `main` without this change. - `card_steps::places_written_after_sending_are_learned` is flaky and passes when run alone. - **Clippy:** `cargo clippy -p victory-gpu --all-targets -- -D warnings` reports the same 4 errors as `main`, none of them new. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01TqPhfCMSaeRyntpNrQy31k
tyr0nsur commented 2026-11-30 13:10:33 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by tyr0nsur on 2026-11-30T13:10:33Z.


I checked the release queue at 202d3f13. The fix already keeps xmem/F7 scratch release synchronous. The sweep queue itself is still unbounded. A blocked driver release can leave old batches alive while the pools replenish, even though their counters no longer include those batches.

The follow-up budgets logical bytes across queued and currently releasing batches. Each batch holds its charge through the last resource drop. Admission uses at most 256 MiB, or one eighth of sampled host headroom when lower. A batch that cannot fit, or one trimmed under critical commit pressure, releases on the caller. This can bring back the release hitch on an overloaded worker. It bounds deferred work and the existing immediate paths still release inline.

For a standalone RTX 4060 test I blocked a 32 MiB batch inside its destructor, queued a 16 MiB batch and tried another 16 MiB with a 48 MiB test cap. DXGI non-local usage went 92 → 76 MiB while the worker was still blocked and then 76 → 28 MiB after it ran again. The original unbounded enqueue also reproduced the pending overflow in an isolated blocked-destructor fixture. 17 diagnostics tests passed and the two queue tests passed on WARP. The test uses artificial delay and does not measure frame time.

Companion commit

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7279462482 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3951#issuecomment-7279462482). Originally posted by [tyr0nsur](https://github.com/tyr0nsur) on 2026-11-30T13:10:33Z. --- I checked the release queue at `202d3f13`. The fix already keeps xmem/F7 scratch release synchronous. The sweep queue itself is still unbounded. A blocked driver release can leave old batches alive while the pools replenish, even though their counters no longer include those batches. The follow-up budgets logical bytes across queued and currently releasing batches. Each batch holds its charge through the last resource drop. Admission uses at most 256 MiB, or one eighth of sampled host headroom when lower. A batch that cannot fit, or one trimmed under critical commit pressure, releases on the caller. This can bring back the release hitch on an overloaded worker. It bounds deferred work and the existing immediate paths still release inline. For a standalone RTX 4060 test I blocked a 32 MiB batch inside its destructor, queued a 16 MiB batch and tried another 16 MiB with a 48 MiB test cap. DXGI non-local usage went **92 → 76 MiB** while the worker was still blocked and then **76 → 28 MiB** after it ran again. The original unbounded enqueue also reproduced the pending overflow in an isolated blocked-destructor fixture. 17 diagnostics tests passed and the two queue tests passed on WARP. The test uses artificial delay and does not measure frame time. [Companion commit](https://github.com/tyr0nsur/VIctory-NVIDIA/commit/cfff9bd89ff8ac29f7ebe0834bbcb0f10e084bf3)
dyshay commented 2026-11-30 14:53:45 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by dyshay on 2026-11-30T14:53:45Z.


Merged for testing into our integration branch dyshay/VIctory-NVIDIA janus-prs (adapted: release apart in the sweep and send::trim; trim_spare_chunks stays synchronous). Builds and the targeted CPU tests pass; a run on an RTX 4090 (Series S, hardware RT) is queued and I'll post the result here.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7282099783 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3951#issuecomment-7282099783). Originally posted by [dyshay](https://github.com/dyshay) on 2026-11-30T14:53:45Z. --- Merged for testing into our integration branch [dyshay/VIctory-NVIDIA `janus-prs`](https://github.com/dyshay/VIctory-NVIDIA/tree/janus-prs) (adapted: release apart in the sweep and `send::trim`; `trim_spare_chunks` stays synchronous). Builds and the targeted CPU tests pass; a run on an RTX 4090 (Series S, hardware RT) is queued and I'll post the result here.
trustno1-coder commented 2026-12-01 18:47:37 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by trustno1-coder on 2026-12-01T18:47:37Z.


Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7321556175 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3951#issuecomment-7321556175). Originally posted by [trustno1-coder](https://github.com/trustno1-coder) on 2026-12-01T18:47:37Z. --- Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
trustno1-coder/VIctory-NVIDIA!3951
No description provided.