Skip to content

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

Closed
Lewandox wants to merge 1 commit into
LooperSalty:mainfrom
Lewandox:perf/indirect-single-lock-and-fast-san
Closed

Lewandox wants to merge 1 commit into
LooperSalty:mainfrom
Lewandox:perf/indirect-single-lock-and-fast-san

Conversation

@Lewandox

Copy link
Copy Markdown
Collaborator

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

Copy link
Copy Markdown
Collaborator Author

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 Lewandox closed this Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant