victory-gpu: back off RemapQueue overflow compaction under disjoint write storms #3733

Manually merged
github merged 1 commit from github-bot/gh-3733 into main 2026-11-30 14:14:44 +00:00 AGit
Owner

@⁠superhero-520 on GitHub · 2026-11-30 05:28 UTC · original
superhero-520:fix/remap-queue-compaction-backoff → main · +231 −28 · 1 files · 1 commits · merged 2026-11-30 14:12 UTC

Summary

Bounds RemapQueue::record() full-queue unpublished compaction under sustained disjoint write storms in crates/victory-gpu/src/descriptor/host.rs, eliminating an O(N^2 \log N) global mutex (REMAPPED) regression introduced in PR #2607 (2fe2d4cc) while preserving 100% of PR #2607's burst-compaction behavior for compressible bursts.

Root Cause

  • REMAP_LIMIT is 1 << 15 (32,768). During live world streaming and GPU-to-CPU landing, watch::landing() -> watch::writing() -> descriptor::host::remapped() records hundreds of thousands of disjoint ranges (e.g. 338,000–462,884 evictions in a 2-minute session on v2026.11.29.05).
  • In PR #2607 (2fe2d4cc), once self.ranges.len() == REMAP_LIMIT with unpub_len > 0, every subsequent disjoint record() call allocates a Vec up to 32,768 entries (512 KiB), drains the unpublished suffix, runs join() (sort_unstable — O(N \log N)), evicts only 1 entry, and re-pushes all entries with self.latest — leaving ranges.len() == REMAP_LIMIT and unpub_len still growing on the very next call, all while holding the global REMAPPED: Mutex<RemapQueue> lock across all landing, write-watch, and xmem threads.
  • Measured impact on RTX 3060 Laptop + Ryzen 7 5800H:
    • v2026.11.28.03 / v2026.11.29.01: landing "opening or noting guards" = 0.8–1.95 ms/frame (merging what was fetched = 3.3–4.8 ms).
    • v2026.11.29.05 (41adb551): landing "opening or noting guards" jumped 12×–25× to 26.5–53.9 ms/frame (merging = 12.4–21.5 ms).

Fix Design (crates/victory-gpu/src/descriptor/host.rs)

  1. Skip mathematically unshrinkable unpub_len < 2 compactions:
    • The ranges.back_mut() fast path immediately above already checked overlap/adjacency against the sole unpublished entry when unpub_len == 1, so draining and sorting 2 guaranteed-disjoint ranges can never shrink the queue.
  2. Geometric compaction cooldown (compact_after):
    • After a compaction pass that still overflows (needed > limit) or shrinks the unpublished suffix by < 25% (unpub.len() * 4 > unpub_len * 3), defer the next full-queue compaction by unpub.len().max(2) records (self.compact_after = self.latest.saturating_add(cooldown)).
    • Intermediate overflow pushes execute in O(1) (pop_front + push_back), bounding disjoint overflow storms to amortized O(\log N) while keeping self.evicted strictly monotonic via self.evicted.max(...).
    • snapshot() resets self.compact_after = 0 so fresh bursts after a snapshot compact immediately; compressible bursts that shrink >= 25% without overflow also keep compact_after = 0.

Verification & Results

Unit & Concurrency Tests (cargo test --locked -p victory-gpu --lib remap_history -- --nocapture --test-threads=1)

  • All existing PR #2607 tests pass unchanged (remap_history_compacts_unpublished_bursts_without_evicting, refresh_remapped_advances_cursor_when_no_slots_match, remap_history_delivers_extended_ranges_and_detects_eviction).
  • New regression tests:
    • remap_history_does_not_thrash_compaction_on_disjoint_overflow_storm: 100,000 disjoint overflow writes at REMAP_LIMIT = 32,768 completed in 8.56 ms with only 16 compactions (monotonic evicted, cooldown cleared on snapshot()).
    • remap_history_repeated_overlapping_and_publish_cycles_never_evict: 8 repeated interleaved overlapping burst + publish cycles with multiple cursors -> 0 evictions and exact coalesced ranges.
    • remap_history_concurrent_overflow_storm_keeps_lock_contention_bounded: 4 writer threads × 25,000 disjoint records (100,000 total) + concurrent snapshot reader at REMAP_LIMIT = 32,768 -> completed in 95.74 ms (365 compactions across 35 snapshots), peak lock wait 1.48 ms, zero panics, monotonic evicted.
  • cargo clippy --locked -p victory-gpu --all-targets, cargo check --profile diag --locked -p victory --features diagnostics, cargo run --locked -p xtask -- policy --staged: all passed with 0 new warnings.

Live Hardware Impact (RTX 3060 Laptop 6 GiB + Ryzen 7 5800H + 16 GB RAM, Series S 540p->1080p DLSS Perf K, RT OFF, warm pipeline library)

  • Measured across 3 repeated warm FG OFF runs on v2026.11.29.05 (41adb551) vs builds including this RemapQueue backoff (both the 2-fix perf build and the combined #2015+#2038+perf build):
    • landing "opening or noting guards": 27.6 ms -> 2.21–2.34 ms/frame (~12× faster), restoring v2026.11.28.03 (1.95 ms).
    • landing "merging what was fetched": 13.1 ms -> 4.53–5.08 ms/frame (~2.6–2.9× faster).
    • Total copyback time: 28.6 ms -> 20.4–21.5 ms/frame (-7.1 to -8.2 ms/frame).
    • Note: these live runs also disabled low-VRAM auto BAR defaults in a separate change; the landing / opening or noting guards metric isolates watch::landing() -> descriptor::host::remapped() lock contention directly (for comparison, disabling VICTORY_SEND_BAR=0 alone without this fix still showed 53.9 ms/frame in opening or noting guards).
    • Zero OOM, zero device-removed; FSR 3 2X and audio unaffected.

Limitations & Known Risks

  • When an overflowed queue receives a burst that starts with disjoint ranges and immediately switches to repeated writes over a few spans before the next snapshot(), compaction waits until the cooldown expires (falling back to the pre-PR-#2607 O(1) ring-buffer eviction during cooldown, which is always sound because evicted advances monotonically and forces a safe rescan on lagging cursors).
  • Tested on single-save 72 s automated live runs; extended 30-minute open-world soak testing is ongoing.

AI Assistance Disclosure

AI-Assisted: Diagnosed, implemented, tested, and documented with AI assistance (Antigravity / Gemini), with all unit/concurrency tests, clippy/policy checks, and live RTX 3060 measurements verified locally.

**@⁠superhero-520** on GitHub · 2026-11-30 05:28 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3733) `superhero-520:fix/remap-queue-compaction-backoff` → `main` · +231 −28 · 1 files · 1 commits · merged 2026-11-30 14:12 UTC ## Summary Bounds `RemapQueue::record()` full-queue unpublished compaction under sustained disjoint write storms in `crates/victory-gpu/src/descriptor/host.rs`, eliminating an $O(N^2 \log N)$ global mutex (`REMAPPED`) regression introduced in PR #2607 (`2fe2d4cc`) while preserving 100% of PR #2607's burst-compaction behavior for compressible bursts. ## Root Cause - `REMAP_LIMIT` is `1 << 15` (`32,768`). During live world streaming and GPU-to-CPU landing, `watch::landing()` -> `watch::writing()` -> `descriptor::host::remapped()` records hundreds of thousands of disjoint ranges (e.g. `338,000`–`462,884` evictions in a 2-minute session on `v2026.11.29.05`). - In PR #2607 (`2fe2d4cc`), once `self.ranges.len() == REMAP_LIMIT` with `unpub_len > 0`, **every subsequent disjoint `record()` call** allocates a `Vec` up to 32,768 entries (512 KiB), drains the unpublished suffix, runs `join()` (`sort_unstable` — $O(N \log N)$), evicts only 1 entry, and re-pushes all entries with `self.latest` — leaving `ranges.len() == REMAP_LIMIT` and `unpub_len` still growing on the very next call, all while holding the global `REMAPPED: Mutex<RemapQueue>` lock across all landing, write-watch, and `xmem` threads. - Measured impact on RTX 3060 Laptop + Ryzen 7 5800H: - `v2026.11.28.03` / `v2026.11.29.01`: `landing` `"opening or noting guards"` = **`0.8–1.95 ms/frame`** (`merging what was fetched` = `3.3–4.8 ms`). - `v2026.11.29.05` (`41adb551`): `landing` `"opening or noting guards"` jumped **12×–25×** to **`26.5–53.9 ms/frame`** (`merging` = `12.4–21.5 ms`). ## Fix Design (`crates/victory-gpu/src/descriptor/host.rs`) 1. **Skip mathematically unshrinkable `unpub_len < 2` compactions**: - The `ranges.back_mut()` fast path immediately above already checked overlap/adjacency against the sole unpublished entry when `unpub_len == 1`, so draining and sorting 2 guaranteed-disjoint ranges can never shrink the queue. 2. **Geometric compaction cooldown (`compact_after`)**: - After a compaction pass that still overflows (`needed > limit`) or shrinks the unpublished suffix by `< 25%` (`unpub.len() * 4 > unpub_len * 3`), defer the next full-queue compaction by `unpub.len().max(2)` records (`self.compact_after = self.latest.saturating_add(cooldown)`). - Intermediate overflow pushes execute in $O(1)$ (`pop_front` + `push_back`), bounding disjoint overflow storms to amortized $O(\log N)$ while keeping `self.evicted` strictly monotonic via `self.evicted.max(...)`. - `snapshot()` resets `self.compact_after = 0` so fresh bursts after a snapshot compact immediately; compressible bursts that shrink `>= 25%` without overflow also keep `compact_after = 0`. ## Verification & Results ### Unit & Concurrency Tests (`cargo test --locked -p victory-gpu --lib remap_history -- --nocapture --test-threads=1`) - All existing PR #2607 tests pass unchanged (`remap_history_compacts_unpublished_bursts_without_evicting`, `refresh_remapped_advances_cursor_when_no_slots_match`, `remap_history_delivers_extended_ranges_and_detects_eviction`). - New regression tests: - `remap_history_does_not_thrash_compaction_on_disjoint_overflow_storm`: 100,000 disjoint overflow writes at `REMAP_LIMIT = 32,768` completed in **`8.56 ms`** with only **`16` compactions** (monotonic `evicted`, cooldown cleared on `snapshot()`). - `remap_history_repeated_overlapping_and_publish_cycles_never_evict`: 8 repeated interleaved overlapping burst + publish cycles with multiple cursors -> `0` evictions and exact coalesced ranges. - `remap_history_concurrent_overflow_storm_keeps_lock_contention_bounded`: 4 writer threads × 25,000 disjoint records (100,000 total) + concurrent snapshot reader at `REMAP_LIMIT = 32,768` -> completed in **`95.74 ms`** (`365` compactions across `35` snapshots), peak lock wait **`1.48 ms`**, zero panics, monotonic `evicted`. - `cargo clippy --locked -p victory-gpu --all-targets`, `cargo check --profile diag --locked -p victory --features diagnostics`, `cargo run --locked -p xtask -- policy --staged`: all passed with 0 new warnings. ### Live Hardware Impact (RTX 3060 Laptop 6 GiB + Ryzen 7 5800H + 16 GB RAM, Series S 540p->1080p DLSS Perf K, RT OFF, warm pipeline library) - Measured across 3 repeated warm FG OFF runs on `v2026.11.29.05` (`41adb551`) vs builds including this `RemapQueue` backoff (both the 2-fix perf build and the combined `#2015+#2038+perf` build): - `landing` `"opening or noting guards"`: **`27.6 ms` -> `2.21–2.34 ms/frame` (~12× faster)**, restoring `v2026.11.28.03` (`1.95 ms`). - `landing` `"merging what was fetched"`: **`13.1 ms` -> `4.53–5.08 ms/frame` (~2.6–2.9× faster)**. - Total `copyback` time: **`28.6 ms` -> `20.4–21.5 ms/frame` (-7.1 to -8.2 ms/frame)**. - Note: these live runs also disabled low-VRAM auto BAR defaults in a separate change; the `landing` / `opening or noting guards` metric isolates `watch::landing()` -> `descriptor::host::remapped()` lock contention directly (for comparison, disabling `VICTORY_SEND_BAR=0` alone without this fix still showed `53.9 ms/frame` in `opening or noting guards`). - Zero OOM, zero device-removed; FSR 3 2X and audio unaffected. ## Limitations & Known Risks - When an overflowed queue receives a burst that starts with disjoint ranges and immediately switches to repeated writes over a few spans *before* the next `snapshot()`, compaction waits until the cooldown expires (falling back to the pre-PR-#2607 $O(1)$ ring-buffer eviction during cooldown, which is always sound because `evicted` advances monotonically and forces a safe rescan on lagging cursors). - Tested on single-save 72 s automated live runs; extended 30-minute open-world soak testing is ongoing. ## AI Assistance Disclosure AI-Assisted: Diagnosed, implemented, tested, and documented with AI assistance (Antigravity / Gemini), with all unit/concurrency tests, clippy/policy checks, and live RTX 3060 measurements verified locally.
PR #2607 (`2fe2d4cc`) compacts the unpublished suffix of `RemapQueue` whenever
the queue reaches `REMAP_LIMIT` (32,768). Under sustained disjoint write/landing
storms in live gameplay (hundreds of thousands of evictions per session), the
queue stays at `REMAP_LIMIT` and every subsequent `remapped()` call allocates a
`Vec`, drains, sorts (`O(N log N)`), and re-pushes up to 32,768 entries while
holding the global `REMAPPED` mutex, inflating `landing` "opening or noting
guards" time 10x-25x (1.3-1.95 ms in v28.03/v29.01 -> 26.5-53.9 ms/frame in
v29.05).

Fix (`crates/victory-gpu/src/descriptor/host.rs`):
- Skip impossible `unpub_len < 2` compactions (the single-entry tail was already
  checked for overlap by the back-entry fast path).
- Add `compact_after` cooldown backoff after overflowing or non-shrinking
  (< 25% reduction) compactions, doubling by `unpub.len().max(2)` and resetting
  to `0` on `snapshot()`, while keeping `evicted` strictly monotonic.
- Preserves full burst compaction for compressible overlapping bursts while
  bounding disjoint overflow storms to amortized O(log N) under `REMAPPED`.

Tests:
- All existing PR #2607 tests pass (`remap_history_compacts_unpublished_bursts_without_evicting`,
  `refresh_remapped_advances_cursor_when_no_slots_match`,
  `remap_history_delivers_extended_ranges_and_detects_eviction`).
- Added 3 regression tests covering 100k disjoint overflow storm, repeated
  overlapping/publish cycles, and 4-writer + reader concurrency/lock-hold latency.

AI-Assisted: Developed and verified with AI assistance (Antigravity / Gemini).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 05:29:54 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-30 06:06 UTC · original · approved these changes

Tested locally merged onto main (41adb551).

  • Merge: Clean merge in crates/victory-gpu/src/descriptor/host.rs.
  • Tests (RTX 5090): cargo test -p victory-gpu --lib descriptor::host::tests:: passed (75 passed; 0 failed; 1 ignored, including all 3 new #3666 regression tests: remap_history_does_not_thrash_compaction_on_disjoint_overflow_storm, remap_history_repeated_overlapping_and_publish_cycles_never_evict, and remap_history_concurrent_overflow_storm_keeps_lock_contention_bounded) with 0 new warnings.

Strong, well-tested fix for the RemapQueue overflow-compaction contention regression (#3666). LGTM.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-30 06:06 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3733#pullrequestreview-6107580094) · **approved these changes** Tested locally merged onto `main` (`41adb551`). - **Merge**: Clean merge in `crates/victory-gpu/src/descriptor/host.rs`. - **Tests (RTX 5090)**: `cargo test -p victory-gpu --lib descriptor::host::tests::` passed (`75 passed; 0 failed; 1 ignored`, including all 3 new `#3666` regression tests: `remap_history_does_not_thrash_compaction_on_disjoint_overflow_storm`, `remap_history_repeated_overlapping_and_publish_cycles_never_evict`, and `remap_history_concurrent_overflow_storm_keeps_lock_contention_bounded`) with 0 new warnings. Strong, well-tested fix for the `RemapQueue` overflow-compaction contention regression (#3666). LGTM. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠Yoruiopz on GitHub · 2026-11-30 07:07 UTC · original

Independent Windows A/B on an RTX 5070 Laptop GPU. I ran the .05 renderer with the same binary, copied checkpoint, controller tape, and warmed cache. Both runs used Series X at 1920×1080, DLSS Performance, 2× frame generation and a 15 FPS render cap. Only the #3733 queue policy was toggled.

Metric Stock .05 policy Backoff policy
Remap records by about 172 seconds after the scene match 3,275,729 3,349,466
Compactions 3,007,855 33,407
Queue entries processed by compaction 743,958,035 5,151,555
Median landing-guard time, summed across threads, in the late 70-second window 6.79 ms 1.13 ms

The comparable early draw blocks covered 768 renders per run. They held about 15 rendered FPS in both runs, with rendered-frame p95 of 79.0 and 80.0 ms. Later draw counts diverged, so those intervals cannot establish a frame-pacing gain. This independently reproduces #3666's excessive queue work and shows the backoff removes most of it on this GPU.

**@⁠Yoruiopz** on GitHub · 2026-11-30 07:07 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3733#issuecomment-7271378804) Independent Windows A/B on an RTX 5070 Laptop GPU. I ran the .05 renderer with the same binary, copied checkpoint, controller tape, and warmed cache. Both runs used Series X at 1920×1080, DLSS Performance, 2× frame generation and a 15 FPS render cap. Only the #3733 queue policy was toggled. | Metric | Stock .05 policy | Backoff policy | |---|---:|---:| | Remap records by about 172 seconds after the scene match | 3,275,729 | 3,349,466 | | Compactions | 3,007,855 | 33,407 | | Queue entries processed by compaction | 743,958,035 | 5,151,555 | | Median landing-guard time, summed across threads, in the late 70-second window | 6.79 ms | 1.13 ms | The comparable early draw blocks covered 768 renders per run. They held about 15 rendered FPS in both runs, with rendered-frame p95 of 79.0 and 80.0 ms. Later draw counts diverged, so those intervals cannot establish a frame-pacing gain. This independently reproduces #3666's excessive queue work and shows the backoff removes most of it on this GPU.
github manually merged commit 05e2e1b4e6 into main 2026-11-30 14:14:44 +00:00
Author
Owner

@⁠ajcorrea on GitHub · 2026-11-30 16:24 UTC · original

Confirming this fix on an 8 GB card, with a bisect that lands on the same commit.

Setup: RTX 3060 Ti 8 GB, Ryzen 7 7800X3D, 32 GB DDR5, Windows 11, Series S profile, 1440p, DLSS Quality + FSR 3 frame generation. Same route on every run, 3–4 min from loading into the world (the streaming-heavy stretch where the hitches showed up after v2026.11.29.05). Release builds, same settings file throughout.

Metrics (from the release log):

  • merge: victory_gpu::land "merging what was fetched", ms per frame summed over all threads (median / max)
  • hitches: frames over 100 ms during gameplay
Build merge (med / max) hitches
v2026.11.29.04 (10161a3) 2.3 / 7.4 86
v2026.11.29.05 (41adb55) 9.1 / 74.1 128
A: .05 minus watch group (#2814, #2604, #2854, #2834, #2795) 8.6 / 54.7 110
B: .05 minus copies group (#2971, #2509, #2116, #2530, #2607) 2.3 / 9.0 78
C: .05 minus abf4fe07 (#2509) 8.5 / 47.0 113
D: .05 minus 9780f5c4 (#2971) 8.3 / 57.2 144
E: .05 minus f37bf099 (#2530) 8.3 / 65.1 110
E + VICTORY_SMALL_COPY=0 (#2116 off) 8.3 / 51.6 97
F: .05 + this PR (223f22f0c) 2.3 / 7.2 69

By elimination the regression is 2fe2d4cc (#2607), and this PR brings merge time back to the .04 level (best hitch count of all runs, no device removals). Glad to see it in v2026.11.30.01. Thanks!

**@⁠ajcorrea** on GitHub · 2026-11-30 16:24 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3733#issuecomment-7284609707) Confirming this fix on an 8 GB card, with a bisect that lands on the same commit. **Setup:** RTX 3060 Ti 8 GB, Ryzen 7 7800X3D, 32 GB DDR5, Windows 11, Series S profile, 1440p, DLSS Quality + FSR 3 frame generation. Same route on every run, 3–4 min from loading into the world (the streaming-heavy stretch where the hitches showed up after v2026.11.29.05). Release builds, same settings file throughout. **Metrics** (from the release log): - *merge*: `victory_gpu::land` "merging what was fetched", ms per frame summed over all threads (median / max) - *hitches*: frames over 100 ms during gameplay | Build | merge (med / max) | hitches | |---|---|---| | v2026.11.29.04 (`10161a3`) | 2.3 / 7.4 | 86 | | v2026.11.29.05 (`41adb55`) | 9.1 / 74.1 | 128 | | A: .05 minus watch group (#2814, #2604, #2854, #2834, #2795) | 8.6 / 54.7 | 110 | | B: .05 minus copies group (#2971, #2509, #2116, #2530, #2607) | 2.3 / 9.0 | 78 | | C: .05 minus `abf4fe07` (#2509) | 8.5 / 47.0 | 113 | | D: .05 minus `9780f5c4` (#2971) | 8.3 / 57.2 | 144 | | E: .05 minus `f37bf099` (#2530) | 8.3 / 65.1 | 110 | | E + `VICTORY_SMALL_COPY=0` (#2116 off) | 8.3 / 51.6 | 97 | | **F: .05 + this PR (`223f22f0c`)** | **2.3 / 7.2** | **69** | By elimination the regression is `2fe2d4cc` (#2607), and this PR brings merge time back to the .04 level (best hitch count of all runs, no device removals). Glad to see it in v2026.11.30.01. Thanks!
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

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