GPU: reduce snapshot pool lock contention #58

Manually merged
github merged 1 commit from gh-pr/58/head into gh-pr/58/base 2026-11-26 20:10:25 +00:00
Owner

@⁠efsebayern on GitHub · 2026-11-26 19:58 UTC · original
efsebayern:perf-snapshot-pool → main · +170 −59 · 1 files · 1 commits · merged 2026-11-26 20:09 UTC

Follow-up to #41. The snapshot pool is shared by submission and worker threads. A checkout scanned the pool for a best fit, every return sorted the pool again, and a miss allocated a fresh buffer while holding the mutex.

Changes

  • Preserve descending capacity order when a buffer is returned or taken. A binary search finds the smallest reusable buffer within the existing size window.
  • Track total capacity under the pool mutex. A return that fits the count and capacity limits skips the retention scan. The memory diagnostics can read the same total directly.
  • Allocate on a pool miss after releasing the mutex. The idle timestamp remains synchronized with checkout, return, and trimming.
  • Keep the retention rules from #41. Normal returns retain the largest buffers, including the existing exception for one oversized buffer. Memory-pressure sweeps keep the smallest buffers up to the post-sweep target. Idle sweeps drain the pool, with deallocation outside the mutex.

Synthetic benchmark

Both Windows release builds contained the #41 locking fix. The baseline was 4ff4ea1 with only the benchmark test added. Independent build directories were used. On an i7-13700K, eight threads performed 80,000 checkout/return pairs per run against a pool prefilled with 384 buffers. VICTORY_SNAPSHOT_POOL=1024, one warm-up per build, then six timed runs per build in alternating order.

Build Median Range
4ff4ea1 194.736 ms 193.269–196.680 ms
Optimized pool 24.104 ms 21.426–29.393 ms

That is about 88% less time for this workload. The benchmark measures the snapshot pool. Gameplay FPS and representative in-game contention are unmeasured.

$env:VICTORY_SNAPSHOT_POOL = '1024'
cargo test --release --locked -p victory-gpu --lib shadow::pool_tests::pool_contention_load -- --ignored --exact --nocapture --test-threads=1

To reproduce the baseline, add only the ignored pool_contention_load test to 4ff4ea1. The existing pool_memory_load passed on both builds. The optimized process had 25,668 KiB of additional private memory after pressure trimming and 0 KiB after the idle trim.

Verification

PR head 44b3757, based on 0b5b906. Windows 11 Pro build 26200, i7-13700K, RTX 4080 SUPER, pinned Rust 1.98.1 MSVC.

  • cargo clippy --workspace --all-targets --locked -- -D warnings and the same command with --all-features both passed.
  • cargo test --locked -p victory-gpu --lib -- --test-threads=1 passed with 404 passed, 0 failed, and 40 ignored.
  • The same package test with --all-features passed with 458 passed, 0 failed, and 40 ignored.
  • cargo xtask policy and the staged asset check passed.

Added focused coverage for best-fit reuse, capacity accounting, size and count limits, and retention of one oversized buffer. The pressure and idle tests also verify the cached capacity after a trim.

Earlier workspace runs on a857333 with the same pool patch passed both configurations with victory-shader excluded and VICTORY_WARP=1. With the shader package included, WARP reported the same six shader failures on the patched and clean a857333 trees. Native full-workspace runs were stopped after shader tests stalled.

Six shader failures reproduced on clean main with WARP
  • ds_min_max_f32_order_floats_and_return_the_old_value
  • legacy_multiply_adds_fuse_their_product_and_flush_their_sources
  • v_permlane16_and_x16_read_the_lanes_their_selectors_pick
  • whole_wave_f64_sum_and_cvt_f32_f64
  • a_lane_mask_joined_with_a_number_is_read_as_the_number_it_is
  • partial_dispatch_with_a_cross_half_wave_op_runs_in_32_lane_waves

AI-assisted with Codex.

**@⁠efsebayern** on GitHub · 2026-11-26 19:58 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/58) `efsebayern:perf-snapshot-pool` → `main` · +170 −59 · 1 files · 1 commits · merged 2026-11-26 20:09 UTC Follow-up to #41. The snapshot pool is shared by submission and worker threads. A checkout scanned the pool for a best fit, every return sorted the pool again, and a miss allocated a fresh buffer while holding the mutex. ## Changes - Preserve descending capacity order when a buffer is returned or taken. A binary search finds the smallest reusable buffer within the existing size window. - Track total capacity under the pool mutex. A return that fits the count and capacity limits skips the retention scan. The memory diagnostics can read the same total directly. - Allocate on a pool miss after releasing the mutex. The idle timestamp remains synchronized with checkout, return, and trimming. - Keep the retention rules from #41. Normal returns retain the largest buffers, including the existing exception for one oversized buffer. Memory-pressure sweeps keep the smallest buffers up to the post-sweep target. Idle sweeps drain the pool, with deallocation outside the mutex. ## Synthetic benchmark Both Windows release builds contained the #41 locking fix. The baseline was `4ff4ea1` with only the benchmark test added. Independent build directories were used. On an i7-13700K, eight threads performed 80,000 checkout/return pairs per run against a pool prefilled with 384 buffers. `VICTORY_SNAPSHOT_POOL=1024`, one warm-up per build, then six timed runs per build in alternating order. | Build | Median | Range | | --- | ---: | ---: | | `4ff4ea1` | 194.736 ms | 193.269–196.680 ms | | Optimized pool | 24.104 ms | 21.426–29.393 ms | That is about 88% less time for this workload. The benchmark measures the snapshot pool. Gameplay FPS and representative in-game contention are unmeasured. ```powershell $env:VICTORY_SNAPSHOT_POOL = '1024' cargo test --release --locked -p victory-gpu --lib shadow::pool_tests::pool_contention_load -- --ignored --exact --nocapture --test-threads=1 ``` To reproduce the baseline, add only the ignored `pool_contention_load` test to `4ff4ea1`. The existing `pool_memory_load` passed on both builds. The optimized process had 25,668 KiB of additional private memory after pressure trimming and 0 KiB after the idle trim. ## Verification PR head `44b3757`, based on `0b5b906`. Windows 11 Pro build 26200, i7-13700K, RTX 4080 SUPER, pinned Rust 1.98.1 MSVC. - `cargo clippy --workspace --all-targets --locked -- -D warnings` and the same command with `--all-features` both passed. - `cargo test --locked -p victory-gpu --lib -- --test-threads=1` passed with 404 passed, 0 failed, and 40 ignored. - The same package test with `--all-features` passed with 458 passed, 0 failed, and 40 ignored. - `cargo xtask policy` and the staged asset check passed. Added focused coverage for best-fit reuse, capacity accounting, size and count limits, and retention of one oversized buffer. The pressure and idle tests also verify the cached capacity after a trim. Earlier workspace runs on `a857333` with the same pool patch passed both configurations with `victory-shader` excluded and `VICTORY_WARP=1`. With the shader package included, WARP reported the same six shader failures on the patched and clean `a857333` trees. Native full-workspace runs were stopped after shader tests stalled. <details> <summary>Six shader failures reproduced on clean main with WARP</summary> - `ds_min_max_f32_order_floats_and_return_the_old_value` - `legacy_multiply_adds_fuse_their_product_and_flush_their_sources` - `v_permlane16_and_x16_read_the_lanes_their_selectors_pick` - `whole_wave_f64_sum_and_cvt_f32_f64` - `a_lane_mask_joined_with_a_number_is_read_as_the_number_it_is` - `partial_dispatch_with_a_cross_half_wave_op_runs_in_32_lane_waves` </details> AI-assisted with Codex.
Keep returned snapshot buffers ordered by capacity and track total capacity so ordinary returns can skip the limit scan. Keep new allocations outside the pool lock, and cover both retention policies plus the contended path.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 20:10:24 +00:00
github manually merged commit 44b37575ea into gh-pr/58/base 2026-11-26 20:10:25 +00:00
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-26 20:04 UTC · original

Thanks for splitting the contention changes out of #41, @⁠efsebayern. On Windows at 44b3757, all six snapshot-pool unit tests passed. I also ran pool_memory_load separately on the 9950X3D. Private memory above baseline fell from 521,332 KiB with the full pool to 25,672 KiB after the pressure sweep and 4 KiB after idle. That independently checks the trim behavior with the cached capacity total. Your contention benchmark measures the pool itself. A gameplay run is still needed to put a number on any frame-time change.

**@⁠TaynanGT** on GitHub · 2026-11-26 20:04 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/58#issuecomment-7202262940) Thanks for splitting the contention changes out of #41, @⁠efsebayern. On Windows at `44b3757`, all six snapshot-pool unit tests passed. I also ran `pool_memory_load` separately on the 9950X3D. Private memory above baseline fell from 521,332 KiB with the full pool to 25,672 KiB after the pressure sweep and 4 KiB after idle. That independently checks the trim behavior with the cached capacity total. Your contention benchmark measures the pool itself. A gameplay run is still needed to put a number on any frame-time change.
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-26 20:10 UTC · original

Merged in 028b4b2 after Windows CI passed. The review confirmed best-fit reuse, cached capacity, and the existing pressure and idle retention rules. The alternating runs give us a clear comparison for the pool workload. A matching Series S route will show how much of that change reaches frame time.

**@⁠TaynanGT** on GitHub · 2026-11-26 20:10 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/58#issuecomment-7202374417) Merged in `028b4b2` after Windows CI passed. The review confirmed best-fit reuse, cached capacity, and the existing pressure and idle retention rules. The alternating runs give us a clear comparison for the pool workload. A matching Series S route will show how much of that change reaches frame time.
This discussion has been locked. Commenting is limited to contributors.
No description provided.