perf(victory-gpu): optimize watch.rs and port.rs hot paths #17

Manually merged
github merged 1 commit from github-bot/gh-17 into mega-upgrade-v3 2026-12-04 20:20:14 +00:00 AGit
Owner

@⁠MahanYTT on GitHub · 2026-12-04 18:56 UTC · original
MahanYTT:perf/watch-port-journal → mega-upgrade-v3 · +522 −149 · 2 files · 1 commits · merged 2026-12-04 20:18 UTC

Summary

Optimizes crates/victory-gpu/src/watch.rs and crates/victory-gpu/src/port.rs hot paths targeting the ~7.2 ms/frame GetWriteWatch / watch-query overhead (4.1 ms submitting thread + 1.88 ms heap_twin + 1.23 ms descriptor) under VICTORY_PORT_JOURNAL=1.

crates/victory-gpu/src/watch.rs

  • Filter not_write_watched in ask_once & reuse ahead_runs: Prevents mapped view/guarded/placeholder ranges from poisoning coalesced ask_once runs and triggering recursive binary-split GetWriteWatch syscall failures.
  • Sharded page noting in ask_once / ask_ahead / ask_rest (note_ahead_batch): Under VICTORY_PORT_JOURNAL=1, notes written pages under the shared JOURNAL read lock + per-shard write locks and acquires JOURNAL.write() only for the O(1) ahead / kept swap, eliminating exclusive lock stalls for concurrent readers (heap_twin, descriptor, texture refreshes).
  • Minimal shard write-locking in writes_with: Locks only shards_of_pages(pages) instead of shards_of(first, last) | shards_of_pages(pages), avoiding locking up to all 64 shards on wide clean/sparse queries.
  • Zero-allocation HeldShards (Empty / One / Many): Replaces heap-allocated Vec<RwLockWriteGuard> with stack-allocated shard guards and a single-shard fast path with no panics/unwraps on title threads.
  • Reusable scratch buffers (ScratchPages + kernel_written_into): Appends GetWriteWatch results directly into caller/TLS buffers instead of allocating a temporary Vec<(usize, u16)> per syscall.
  • Shard-lock caching in parts_written: Caches the active shard RwLockReadGuard across consecutive pages in the same 64 MiB shard and adds fast paths for !parts_on() and empty Shard::parts.
  • 64 MiB leaf max_epoch skipping in PageEpochs: Tracks per-leaf max_epoch to skip clean 64 MiB leaves in one atomic load during collect_after, any_after, and all_within.
  • Allocation-free Tracked::take with dense SeenPages: Scans PageEpochs / Notes directly inside writes_with against O(1) dense page-epoch storage (for ranges <= 4 GiB, BTreeMap fallback above) and reuses the already-held JOURNAL read lock for parts_written.

crates/victory-gpu/src/port.rs

  • RwLock<Vec<Region>> & unlocked D3D12 placement: Replaces Mutex<Vec<Region>> with RwLock, clones (start, heap, view) under a short read lock (or double-checked write lock on first open), and calls crate::inplace::place / GetGPUVirtualAddress completely unlocked.
  • Lock-free BOUNDS fast-path & Acquire/Release ordering: Adds an empty-bounds early return to section_gone, short-circuits wanted on len == 0, and uses Release/Acquire on BOUNDS.

Verification

  • cargo clippy -p victory-gpu --target x86_64-pc-windows-gnu --tests -- -D warnings (Rust 1.98.1): 0 warnings, 0 errors.
  • cargo clippy -p victory-gpu --target x86_64-pc-windows-gnu --features diagnostics --lib -- -D warnings (Rust 1.98.1): 0 warnings, 0 errors.
  • Focused unit tests added in both watch.rs and port.rs; standalone host unit test verification passed (2 passed; 0 failed).
**@⁠MahanYTT** on GitHub · 2026-12-04 18:56 UTC · [original](https://github.com/MahanYTT/VIctory-MA/pull/17) `MahanYTT:perf/watch-port-journal` → `mega-upgrade-v3` · +522 −149 · 2 files · 1 commits · merged 2026-12-04 20:18 UTC ## Summary Optimizes `crates/victory-gpu/src/watch.rs` and `crates/victory-gpu/src/port.rs` hot paths targeting the ~7.2 ms/frame `GetWriteWatch` / watch-query overhead (`4.1 ms` submitting thread + `1.88 ms` `heap_twin` + `1.23 ms` `descriptor`) under `VICTORY_PORT_JOURNAL=1`. ### `crates/victory-gpu/src/watch.rs` - **Filter `not_write_watched` in `ask_once` & reuse `ahead_runs`**: Prevents mapped view/guarded/placeholder ranges from poisoning coalesced `ask_once` runs and triggering recursive binary-split `GetWriteWatch` syscall failures. - **Sharded page noting in `ask_once` / `ask_ahead` / `ask_rest` (`note_ahead_batch`)**: Under `VICTORY_PORT_JOURNAL=1`, notes written pages under the shared `JOURNAL` read lock + per-shard write locks and acquires `JOURNAL.write()` only for the O(1) `ahead` / `kept` swap, eliminating exclusive lock stalls for concurrent readers (`heap_twin`, `descriptor`, texture refreshes). - **Minimal shard write-locking in `writes_with`**: Locks only `shards_of_pages(pages)` instead of `shards_of(first, last) | shards_of_pages(pages)`, avoiding locking up to all 64 shards on wide clean/sparse queries. - **Zero-allocation `HeldShards` (`Empty` / `One` / `Many`)**: Replaces heap-allocated `Vec<RwLockWriteGuard>` with stack-allocated shard guards and a single-shard fast path with no panics/unwraps on title threads. - **Reusable scratch buffers (`ScratchPages` + `kernel_written_into`)**: Appends `GetWriteWatch` results directly into caller/TLS buffers instead of allocating a temporary `Vec<(usize, u16)>` per syscall. - **Shard-lock caching in `parts_written`**: Caches the active shard `RwLockReadGuard` across consecutive pages in the same 64 MiB shard and adds fast paths for `!parts_on()` and empty `Shard::parts`. - **64 MiB leaf `max_epoch` skipping in `PageEpochs`**: Tracks per-leaf `max_epoch` to skip clean 64 MiB leaves in one atomic load during `collect_after`, `any_after`, and `all_within`. - **Allocation-free `Tracked::take` with dense `SeenPages`**: Scans `PageEpochs` / `Notes` directly inside `writes_with` against O(1) dense page-epoch storage (for ranges <= 4 GiB, `BTreeMap` fallback above) and reuses the already-held `JOURNAL` read lock for `parts_written`. ### `crates/victory-gpu/src/port.rs` - **`RwLock<Vec<Region>>` & unlocked D3D12 placement**: Replaces `Mutex<Vec<Region>>` with `RwLock`, clones `(start, heap, view)` under a short read lock (or double-checked write lock on first open), and calls `crate::inplace::place` / `GetGPUVirtualAddress` completely unlocked. - **Lock-free `BOUNDS` fast-path & `Acquire`/`Release` ordering**: Adds an empty-bounds early return to `section_gone`, short-circuits `wanted` on `len == 0`, and uses `Release`/`Acquire` on `BOUNDS`. ## Verification - `cargo clippy -p victory-gpu --target x86_64-pc-windows-gnu --tests -- -D warnings` (Rust 1.98.1): **0 warnings, 0 errors**. - `cargo clippy -p victory-gpu --target x86_64-pc-windows-gnu --features diagnostics --lib -- -D warnings` (Rust 1.98.1): **0 warnings, 0 errors**. - Focused unit tests added in both `watch.rs` and `port.rs`; standalone host unit test verification passed (`2 passed; 0 failed`).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-04 19:00:29 +00:00
github manually merged commit 4ba58378c8 into mega-upgrade-v3 2026-12-04 20:20:14 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.