perf(sweeping): curb eviction budget overruns and fix BackOff/drain edge cases #5

Manually merged
github merged 2 commits from github-bot/gh-5 into mega-upgrade-v3 2026-12-04 20:20:12 +00:00 AGit
Owner

@⁠MahanYTT on GitHub · 2026-12-04 17:39 UTC · original
MahanYTT:perf/slot-evict-fix → mega-upgrade-v3 · +197 −53 · 2 files · 2 commits · merged 2026-12-04 20:18 UTC

Summary

Addresses the texture-sweep / slot-eviction overhead observed in the 170s RTX 5070 Ti playtest log (VICTORY_SLOT_EVICT=1, VICTORY_TEX_PARK=1, VICTORY_TEXTURE_POOL=1), where 51 idle-texture sweep looks averaged 3.00 ms (max 16.4 ms, 42/50 walks hitting the 3 ms budget) while VICTORY_SLOT_EVICT reclaimed 0 textures (0 MB) across 68,918 idle-looking textures (28,832 bindless-pinned).

Root Causes & Changes in crates/victory-gpu/src/sweeping.rs

  1. HELD_MS too short (5_000 ms → 30_000 ms): With 68,918 textures and 28,832+ bindless-pinned textures, a 5 s hold-skip window expired before the next sweep, forcing resource::let_go_idle to repeatedly collect, sort, and lock-check the same pinned textures on every sweep. Raising HELD_MS to 30 s aligns it with VICTORY_SLOT_EVICT_BACKOFF_MS.
  2. CLOCK_EVERY budget overshoot (64 → 32): Polling the clock every 32 entries instead of 64 halves time-budget overshoot when per-entry visits acquire per-texture locks.
  3. False timed_out = true in evict_window_drain: out_of_time() was checked before checking whether candidates had any remaining items. If the deadline expired while processing the final candidate, timed_out was set to true despite zero candidates remaining, which caused EvictionPass::rest_after to refuse entering BackOff.
  4. BackOff::over zero/small-budget bug & RISE_PERCENT (2 → 5): When budget < 100 (including 0), budget / 100 * RISE_PERCENT evaluated to 0, making used >= self.used.saturating_add(0) unconditionally true and cancelling backoff immediately. Guarded with rise > 0 and raised RISE_PERCENT to 5% (~730 MB on a 14.6 GB budget) to avoid early wake-ups on normal frame-to-frame VRAM jitter.

Unit Tests Added (crates/victory-gpu/src/sweeping.rs)

  • evict_window_drain_does_not_report_timeout_when_queue_is_exhausted
  • backoff_does_not_end_early_when_budget_is_zero_or_small

Note on crates/victory-gpu/src/pool.rs: Because pool.rs is 4,509 lines (~200 KB) and GitHub MCP's push_files API requires transmitting the entire file verbatim in one call, the pool.rs optimization patch (Ranges secondary (size, start) index, O(1) free_bytes/largest() fast-rejects in Pool::cut & Pool::best_fit, zero-panic Pool::cut, skipping the redundant second mutex lock on BlockGrowth::Deferred, and fast-pathing CARD_ROOM before FirstUploadBudget::lock_growth() + DXGI video_memory()) is provided as a companion git apply patch (pool-perf-fix.patch) to apply cleanly onto this branch.

Verification

  • Ran all 17 unit tests in crates/victory-gpu/src/sweeping.rs locally with rustc --edition 2024 --test (17/17 passing).
  • Ready for windows-latest CI validation (cargo clippy --workspace --all-targets --target x86_64-pc-windows-msvc --locked -- -D warnings & cargo test --workspace --locked).
**@⁠MahanYTT** on GitHub · 2026-12-04 17:39 UTC · [original](https://github.com/MahanYTT/VIctory-MA/pull/5) `MahanYTT:perf/slot-evict-fix` → `mega-upgrade-v3` · +197 −53 · 2 files · 2 commits · merged 2026-12-04 20:18 UTC ## Summary Addresses the texture-sweep / slot-eviction overhead observed in the 170s RTX 5070 Ti playtest log (`VICTORY_SLOT_EVICT=1`, `VICTORY_TEX_PARK=1`, `VICTORY_TEXTURE_POOL=1`), where 51 idle-texture sweep looks averaged 3.00 ms (max 16.4 ms, 42/50 walks hitting the 3 ms budget) while `VICTORY_SLOT_EVICT` reclaimed 0 textures (0 MB) across 68,918 idle-looking textures (28,832 bindless-pinned). ### Root Causes & Changes in `crates/victory-gpu/src/sweeping.rs` 1. **`HELD_MS` too short (`5_000` ms → `30_000` ms)**: With 68,918 textures and 28,832+ bindless-pinned textures, a 5 s hold-skip window expired before the next sweep, forcing `resource::let_go_idle` to repeatedly collect, sort, and lock-check the same pinned textures on every sweep. Raising `HELD_MS` to 30 s aligns it with `VICTORY_SLOT_EVICT_BACKOFF_MS`. 2. **`CLOCK_EVERY` budget overshoot (`64` → `32`)**: Polling the clock every 32 entries instead of 64 halves time-budget overshoot when per-entry visits acquire per-texture locks. 3. **False `timed_out = true` in `evict_window_drain`**: `out_of_time()` was checked before checking whether `candidates` had any remaining items. If the deadline expired while processing the final candidate, `timed_out` was set to `true` despite zero candidates remaining, which caused `EvictionPass::rest_after` to refuse entering `BackOff`. 4. **`BackOff::over` zero/small-budget bug & `RISE_PERCENT` (`2` → `5`)**: When `budget < 100` (including `0`), `budget / 100 * RISE_PERCENT` evaluated to `0`, making `used >= self.used.saturating_add(0)` unconditionally `true` and cancelling backoff immediately. Guarded with `rise > 0` and raised `RISE_PERCENT` to 5% (~730 MB on a 14.6 GB budget) to avoid early wake-ups on normal frame-to-frame VRAM jitter. ### Unit Tests Added (`crates/victory-gpu/src/sweeping.rs`) - `evict_window_drain_does_not_report_timeout_when_queue_is_exhausted` - `backoff_does_not_end_early_when_budget_is_zero_or_small` > **Note on `crates/victory-gpu/src/pool.rs`:** Because `pool.rs` is 4,509 lines (~200 KB) and GitHub MCP's `push_files` API requires transmitting the entire file verbatim in one call, the `pool.rs` optimization patch (`Ranges` secondary `(size, start)` index, O(1) `free_bytes`/`largest()` fast-rejects in `Pool::cut` & `Pool::best_fit`, zero-panic `Pool::cut`, skipping the redundant second mutex lock on `BlockGrowth::Deferred`, and fast-pathing `CARD_ROOM` before `FirstUploadBudget::lock_growth()` + DXGI `video_memory()`) is provided as a companion `git apply` patch (`pool-perf-fix.patch`) to apply cleanly onto this branch. ### Verification - Ran all 17 unit tests in `crates/victory-gpu/src/sweeping.rs` locally with `rustc --edition 2024 --test` (17/17 passing). - Ready for `windows-latest` CI validation (`cargo clippy --workspace --all-targets --target x86_64-pc-windows-msvc --locked -- -D warnings` & `cargo test --workspace --locked`).
- Increase HELD_MS from 5s to 30s so bindless-pinned textures are not
  re-collected, sorted, and lock-checked on every sweep.
- Halve CLOCK_EVERY from 64 to 32 to reduce time-budget overshoot during
  per-texture mutex visits.
- Check candidates.is_empty() before out_of_time() in evict_window_drain
  so an exhausted queue does not falsely mark timed_out=true and block
  EvictionPass::rest_after from engaging BackOff.
- Guard BackOff::over against budget < 100 (where integer division yielded
  a 0-byte rise threshold) and raise RISE_PERCENT from 2% to 5% to avoid
  canceling backoff on normal frame-to-frame VRAM jitter.
- Add focused unit tests for evict_window_drain exhaustion and small/zero
  budget BackOff handling.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-04 17:44:38 +00:00
github manually merged commit 4ba58378c8 into mega-upgrade-v3 2026-12-04 20:20:11 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.