perf(victory-gpu): single-lock indirect::learn, O(1) clean check, and zero-HashMap sanitize pass #405

Closed
github-bot wants to merge 1 commit from github-bot/gh-405 into main AGit
Owner

@⁠Lewandox on GitHub · 2026-11-26 17:35 UTC · original
Lewandox:perf/indirect-single-lock-and-fast-san → main · +60 −14 · 2 files · 1 commits · closed without merging

Summary

Reduces per-draw CPU overhead and removes temporary HashMap churn on the indirect-draw sanitization path (third_party/victory/crates/victory-gpu/src/indirect.rs):

  1. Single lock & lookup in learn():
    • Previously learn() locked LEARNED, called contains_key(&at), dropped the lock, then immediately re-locked LEARNED to prune and insert(at, (kind, frame)).
    • Now acquires LEARNED once, prunes on frame change, and checks insert(...).is_none() to count unseen records — cutting mutex acquisitions and BTreeMap lookups in half on every indirect draw.
  2. O(1) clean fast path in San::is_clean():
    • Previously every clean check linearly scanned every declared write range in self.writes, even when no write had been declared since the sanitize pass (s == self.seq).
    • Now short-circuits immediately in O(1) when s == self.seq.
  3. Zero-HashMap disjoint range collection in pass():
    • Coalesces overlapping written ranges into sorted disjoint intervals (coalesce_ranges) before querying LEARNED (BTreeMap::range), collecting (at, kind) directly in ascending address order without allocating a temporary HashMap (also giving the GPU sanitize compute shader monotonically increasing buffer offsets).
  4. Unit tests (indirect/san_tests.rs):
    • Verifies coalesce_ranges merges overlapping/adjacent ranges and preserves disjoint intervals.
    • Verifies learn() prunes entries older than two frames and counts unseen records once per sight under a single lock.

Verification

  • cargo test -p victory-gpu --lib indirect:: (default and --features diagnostics)
  • cargo xtask policy inside third_party/victory
**@⁠Lewandox** on GitHub · 2026-11-26 17:35 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/405) `Lewandox:perf/indirect-single-lock-and-fast-san` → `main` · +60 −14 · 2 files · 1 commits · closed without merging ## Summary Reduces per-draw CPU overhead and removes temporary `HashMap` churn on the indirect-draw sanitization path (`third_party/victory/crates/victory-gpu/src/indirect.rs`): 1. **Single lock & lookup in `learn()`**: - Previously `learn()` locked `LEARNED`, called `contains_key(&at)`, dropped the lock, then immediately re-locked `LEARNED` to prune and `insert(at, (kind, frame))`. - Now acquires `LEARNED` once, prunes on frame change, and checks `insert(...).is_none()` to count unseen records — cutting mutex acquisitions and `BTreeMap` lookups in half on every indirect draw. 2. **O(1) clean fast path in `San::is_clean()`**: - Previously every clean check linearly scanned every declared write range in `self.writes`, even when no write had been declared since the sanitize pass (`s == self.seq`). - Now short-circuits immediately in O(1) when `s == self.seq`. 3. **Zero-`HashMap` disjoint range collection in `pass()`**: - Coalesces overlapping written ranges into sorted disjoint intervals (`coalesce_ranges`) before querying `LEARNED` (`BTreeMap::range`), collecting `(at, kind)` directly in ascending address order without allocating a temporary `HashMap` (also giving the GPU sanitize compute shader monotonically increasing buffer offsets). 4. **Unit tests** (`indirect/san_tests.rs`): - Verifies `coalesce_ranges` merges overlapping/adjacent ranges and preserves disjoint intervals. - Verifies `learn()` prunes entries older than two frames and counts unseen records once per sight under a single lock. ## Verification - `cargo test -p victory-gpu --lib indirect::` (default and `--features diagnostics`) - `cargo xtask policy` inside `third_party/victory`
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 17:36:29 +00:00
github-bot closed this pull request 2026-11-26 19:34:46 +00:00
Author
Owner

@⁠Lewandox on GitHub · 2026-11-26 19:16 UTC · original

Closing as superseded after #409 (\indirect.rs\ was rewritten around the GPU compute clamp shader and \indirect::batch, replacing the old CPU sanitize path).

**@⁠Lewandox** on GitHub · 2026-11-26 19:16 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/405#issuecomment-7201387067) Closing as superseded after #409 (\indirect.rs\ was rewritten around the GPU compute clamp shader and \indirect::batch\, replacing the old CPU sanitize path).

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.