perf(gpu): scope standalone ahead queries to covered page ranges #312

Open
github-bot wants to merge 9 commits from github-bot/gh-312 into main AGit
Owner

@⁠tommiehansen on GitHub · 2026-12-03 12:21 UTC · original
tommiehansen:perf/phase3-scoped-watch → main · +422 −24 · 3 files · 9 commits · open

What this does

Scope standalone ahead queries to covered page ranges.

Checks

  • Off-by-default and main parity: Off by default; whole-submission queries retain full-range hold.
  • Docs move with code: settings documentation is present; F1 menu exposure is deferred until the upstream menu reorganization is incorporated. The experimental switch remains available via the command line.
  • No unrelated cleanup: One scoped write-watch query subject.
  • A test must exercise the change: asking_ranges_matches_bruteforce_over_randomized_operations and independent native tests reported; interleaving regression and lock-order invariant added; all five targeted tests passed at current head. Explicit fail-before evidence remains.
  • Queue checked on 2026-12-04: #381 and #513 also touch watch, independent intent; review lock interactions.
  • Run cargo xtask policy on the final revision; no new game assets or build output intended.

Verified

Current review head: 31a6bd57c590d6e7758baf0d1b6158c82de258d5. Existing measurements and commands are retained below at their original revisions. No fresh compile, policy or hardware test is claimed by this metadata review.

Cost

Smaller claimed query range, potential mutex cost; no proven frame-time benefit.


Detailed implementation and historical validation

Problem

Standalone ahead batches take a whole-address-space write-watch hold even when they query a few disjoint ranges. This can unnecessarily stall other threads asking unrelated pages.

Implementation and invariants

With VICTORY_ASK_AHEAD_SCOPED=1, acquire the coalesced union of actual kernel query runs atomically, including gaps queried while combining neighboring intervals. Keep the claim until the journal publication completes. Preserve serialization among standalone ahead batches and retain the full-range hold for two-part submission queries. Overlapping resets and publication still serialize; the same kernel and unmapped-view checks remain in force. Unset the switch to restore the baseline.

Source and expected impact

Inspired by MiniVI #324. Its broader Windows implementation reported average 13.61 → 16.54 FPS in one world run and virtually unchanged FPS in a GPU-bound 4K run. This narrower xmem change targets the standalone CPU wait only. No expected FPS is inferred.

External benchmark context

MiniVI #324, RTX 4060 Ti 8 GB, paired 90-second runs:

Metric Before After
1440p world average FPS 13.61 16.54 (+21.5%)
1440p median FPS 14.6 15.1
4K DLSS Quality average FPS 6.49 6.50

Its diagnostics also reported range-lock waits of 1.16–1.28 ms versus 0.43–0.45 ms per frame. Its implementation changes both ahead and rest submission queries; this PR deliberately preserves the full-range hold for two-part submission queries. The results are not predictions for xmem.

Validation

The portable interval test passed for ordered, adjacent and overlapping ranges. The diagnostics Windows-target check and diff check passed. Measure standalone ask waits, CPU stall time and write/coherence parity, including mixed with existing refresh batching.

Hardware verification

No local game execution or GPU benchmarking was available. Please A/B the same save and route on RX 9060 XT 16 GB at native 1080p and RX 9070 XT at native 1440p, with RT on and frame generation off.

Pass 2B — sorted range table and native write-watch validation

The sorted table in c105943 keeps each holder’s half-open ranges distinct. Insertion and overlap checks share the existing lock, and exact-match removal drops only the owning guard’s entries. The preceding cbc421b has the same watch.rs implementation as e7c3699, which uses the Vec-based range table. The measurements below are from the published local microbenchmarks, Apple M5, CPU only, rustc -O, eight A/B/B/A blocks. They compare two implementations of the interval operations.

Interval operation Vec Sorted disjoint table Change
Single disjoint hold/drop, 256 existing ranges 151.6 ns 72.2 ns −52.42%
Single overlap near the end, 256 existing ranges 66.2 ns 4.1 ns −93.82%
Scoped batch hold/drop, 256 requested and 16 existing ranges 3,038.4 ns 668.2 ns −78.01%

The exact timing driver and raw samples from that run are unavailable here. The four portable production tests were rerun successfully at c105943:

rustc --edition 2024 --test crates/victory-gpu/src/watch/asking_ranges.rs -o /tmp/victory-asking-ranges
/tmp/victory-asking-ranges

Independent native Windows validation at c105943 exercised GetWriteWatch and confirmed entry into the scoped branch with the switch set. It also checked 400,000 randomized hold operations, 100,000 run-builder inputs, overlapping and touching holds, and mixed ask_ahead, writes and ask_once calls. The full library test run had the same five failures as main under the reviewer’s test setup, including the shared flaky write-watch test. Standalone ahead batches still serialize with each other. Linux/Wine contention and frame-time impact remain unverified.

Pending: GitHub reports a merge conflict; resolve against main before ready.

Follow-up review fixes (2026-12-04)

Head: 31a6bd57c590d6e7758baf0d1b6158c82de258d5.

Document the AHEAD_BATCH/ASKING lock-order invariant. Extract the scoped acquisition and post-wait publication check into a guard helper, keeping range-guard release before batch-mutex release. Added scoped_wait_preserves_whole_submission_publication, run in isolation using cargo test --locked -p victory-gpu --lib --features diagnostics -- scoped_wait_preserves_whole_submission_publication --ignored --test-threads=1.

Pinned CI audit started for this revision. Final-head compilation, tests and policy results are pending; historical measurements have not been relabelled.

Final-head CI update

At 31a6bd57c590d6e7758baf0d1b6158c82de258d5, Windows MSVC cargo check --locked -p victory-gpu --all-targets --features diagnostics and 5 targeted tests (asking_ranges::tests plus isolated scoped_wait_preserves_whole_submission_publication) passed, with zero test failures (audit). The upstream merge snapshot also passed asset policy; with the independent repository-wide policy fix #528 applied, all four switch tests pass (verification). No dependency on #528 for runtime behavior. Hardware/gameplay verification and any remaining checklist items are still open for review. Ready for review does not imply those are completed.

Queue refresh — 2026-12-05

Merged upstream main b581f7e0a8086158953a64068ba29305d5450d68 into the existing branch without rewriting history. New head: d34f1cb433b891a84f6740ac2b644a8c7dedc916.

Fresh pinned CI audit is the verification record for this revision; previous tests apply to the previously stated heads. #528 remains a separate policy prerequisite, not a runtime dependency. No new gameplay or GPU timing claim.

**@⁠tommiehansen** on GitHub · 2026-12-03 12:21 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/312) `tommiehansen:perf/phase3-scoped-watch` → `main` · +422 −24 · 3 files · 9 commits · open ## What this does Scope standalone ahead queries to covered page ranges. ## Checks - [ ] Off-by-default and main parity: Off by default; whole-submission queries retain full-range hold. - [ ] Docs move with code: settings documentation is present; F1 menu exposure is deferred until the upstream menu reorganization is incorporated. The experimental switch remains available via the command line. - [x] No unrelated cleanup: One scoped write-watch query subject. - [ ] A test must exercise the change: `asking_ranges_matches_bruteforce_over_randomized_operations` and independent native tests reported; interleaving regression and lock-order invariant added; all five targeted tests passed at current head. Explicit fail-before evidence remains. - [x] Queue checked on 2026-12-04: #381 and #513 also touch watch, independent intent; review lock interactions. - [ ] Run `cargo xtask policy` on the final revision; no new game assets or build output intended. ## Verified Current review head: `31a6bd57c590d6e7758baf0d1b6158c82de258d5`. Existing measurements and commands are retained below at their original revisions. No fresh compile, policy or hardware test is claimed by this metadata review. ## Cost Smaller claimed query range, potential mutex cost; no proven frame-time benefit. --- ## Detailed implementation and historical validation ## Problem Standalone ahead batches take a whole-address-space write-watch hold even when they query a few disjoint ranges. This can unnecessarily stall other threads asking unrelated pages. ## Implementation and invariants With `VICTORY_ASK_AHEAD_SCOPED=1`, acquire the coalesced union of actual kernel query runs atomically, including gaps queried while combining neighboring intervals. Keep the claim until the journal publication completes. Preserve serialization among standalone ahead batches and retain the full-range hold for two-part submission queries. Overlapping resets and publication still serialize; the same kernel and unmapped-view checks remain in force. Unset the switch to restore the baseline. ## Source and expected impact Inspired by [MiniVI #324](https://github.com/Androtim/MiniVI/pull/324). Its broader Windows implementation reported average 13.61 → 16.54 FPS in one world run and virtually unchanged FPS in a GPU-bound 4K run. This narrower xmem change targets the standalone CPU wait only. No expected FPS is inferred. ## External benchmark context [MiniVI #324](https://github.com/Androtim/MiniVI/pull/324), RTX 4060 Ti 8 GB, paired 90-second runs: | Metric | Before | After | |---|---:|---:| | 1440p world average FPS | 13.61 | 16.54 (+21.5%) | | 1440p median FPS | 14.6 | 15.1 | | 4K DLSS Quality average FPS | 6.49 | 6.50 | Its diagnostics also reported range-lock waits of 1.16–1.28 ms versus 0.43–0.45 ms per frame. Its implementation changes both ahead and rest submission queries; this PR deliberately preserves the full-range hold for two-part submission queries. The results are not predictions for xmem. ## Validation The portable interval test passed for ordered, adjacent and overlapping ranges. The diagnostics Windows-target check and diff check passed. Measure standalone ask waits, CPU stall time and write/coherence parity, including mixed with existing refresh batching. ## Hardware verification No local game execution or GPU benchmarking was available. Please A/B the same save and route on RX 9060 XT 16 GB at native 1080p and RX 9070 XT at native 1440p, with RT on and frame generation off. ### Pass 2B — sorted range table and native write-watch validation The sorted table in `c105943` keeps each holder’s half-open ranges distinct. Insertion and overlap checks share the existing lock, and exact-match removal drops only the owning guard’s entries. The preceding `cbc421b` has the same `watch.rs` implementation as `e7c3699`, which uses the Vec-based range table. The measurements below are from the [published local microbenchmarks](https://git.gtahub.st/github/lobomfz--VIctory-xmem/pulls/312), Apple M5, CPU only, `rustc -O`, eight A/B/B/A blocks. They compare two implementations of the interval operations. | Interval operation | Vec | Sorted disjoint table | Change | |---|---:|---:|---:| | Single disjoint hold/drop, 256 existing ranges | 151.6 ns | 72.2 ns | −52.42% | | Single overlap near the end, 256 existing ranges | 66.2 ns | 4.1 ns | −93.82% | | Scoped batch hold/drop, 256 requested and 16 existing ranges | 3,038.4 ns | 668.2 ns | −78.01% | The exact timing driver and raw samples from that run are unavailable here. The four portable production tests were rerun successfully at `c105943`: ```sh rustc --edition 2024 --test crates/victory-gpu/src/watch/asking_ranges.rs -o /tmp/victory-asking-ranges /tmp/victory-asking-ranges ``` [Independent native Windows validation at `c105943`](https://git.gtahub.st/github/lobomfz--VIctory-xmem/pulls/312) exercised `GetWriteWatch` and confirmed entry into the scoped branch with the switch set. It also checked 400,000 randomized hold operations, 100,000 run-builder inputs, overlapping and touching holds, and mixed `ask_ahead`, `writes` and `ask_once` calls. The full library test run had the same five failures as main under the reviewer’s test setup, including the shared flaky write-watch test. Standalone ahead batches still serialize with each other. Linux/Wine contention and frame-time impact remain unverified. **Pending:** GitHub reports a merge conflict; resolve against main before ready. ### Follow-up review fixes (2026-12-04) Head: `31a6bd57c590d6e7758baf0d1b6158c82de258d5`. Document the AHEAD_BATCH/ASKING lock-order invariant. Extract the scoped acquisition and post-wait publication check into a guard helper, keeping range-guard release before batch-mutex release. Added `scoped_wait_preserves_whole_submission_publication`, run in isolation using `cargo test --locked -p victory-gpu --lib --features diagnostics -- scoped_wait_preserves_whole_submission_publication --ignored --test-threads=1`. Pinned [CI audit](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47438443784) started for this revision. Final-head compilation, tests and policy results are pending; historical measurements have not been relabelled. ### Final-head CI update At `31a6bd57c590d6e7758baf0d1b6158c82de258d5`, Windows MSVC `cargo check --locked -p victory-gpu --all-targets --features diagnostics` and 5 targeted tests (asking_ranges::tests plus isolated scoped_wait_preserves_whole_submission_publication) passed, with zero test failures ([audit](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47438443784)). The upstream merge snapshot also passed asset policy; with the independent repository-wide policy fix #528 applied, all four switch tests pass ([verification](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47440075807)). No dependency on #528 for runtime behavior. Hardware/gameplay verification and any remaining checklist items are still open for review. Ready for review does not imply those are completed. ### Queue refresh — 2026-12-05 Merged upstream main `b581f7e0a8086158953a64068ba29305d5450d68` into the existing branch without rewriting history. New head: `d34f1cb433b891a84f6740ac2b644a8c7dedc916`. [Fresh pinned CI audit](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47466412636) is the verification record for this revision; previous tests apply to the previously stated heads. #528 remains a separate policy prerequisite, not a runtime dependency. No new gameplay or GPU timing claim.
Hold the union of actual kernel query runs, including their bridged gaps, until publication. Keep the existing global hold for the two-part submission query. Disjoint CPU queries can proceed, overlapping resets still serialize. Inspired by MiniVI #324. The portable overlap test and diagnostics Windows-target check passed.
An ahead batch can have two requested intervals but no combined kernel runs. Use the original full hold and empty publication for that case so it cannot leave a previous journal entry standing.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-03 12:26:43 +00:00
Preserve every original production-code hunk and integrate the switch documentation alongside the newly added upstream settings. No behavior changes beyond the existing PR.
Author
Owner

@⁠Kal0s-design on GitHub · 2026-12-03 19:39 UTC · original

Tested e7c3699 on Windows 11 natively (MSVC, toolchain 1.98.1), so the write watch is the real GetWriteWatch with the reset flag, not Wine. CPU-only, victory-gpu lib tests.

Reading the change I didn't find a problem. AheadAsking::hold checks for overlap and inserts the union under the same ASKING lock, so two overlapping holders can't both get in, and hold_all and a scoped hold wait for each other. Lock order is AHEAD_BATCH then ASKING then the journal, and ask_once passes held=true so it never takes AHEAD_BATCH. The guards outlive journal publication and get dropped on the early kept return and on unwind. The reset only ever covers a run span or half of one, which is inside the claim, and the gap pages inside a run are part of the span. With the variable unset it's the same hold_all and publication as before.

One thing worth knowing is that the existing tests never reach the scoped branch. I added a temporary print there and nothing in the suite hit it with the variable set, since the only standalone ask_ahead in the tests passes a single range. So I wrote a few throwaway tests locally (not pushed). Disjoint holders and a writes-style hold in the gap between two runs get through, overlapping ones block until drop, hold_all and a scoped hold block each other both ways, and a panic while holding releases the ranges. On two small write-watched allocations, ask_ahead over three ranges of the first one answers the first one's written page from the journal and leaves a write in the second allocation for writes() to find. Three threads mixing ask_ahead, writes and ask_once finished without hanging. All of these passed with the variable set, and the last two also with it unset.

Also, because of AHEAD_BATCH two standalone batches still run one at a time even when they don't overlap. The doc comment says so, I'm just mentioning it in case the title reads like they run in parallel.

Results

  • watch:: tests in debug and release, unset, =0 and =1, all pass except the_rest_of_the_one_asking_has_a_number_of_its_own, which fails now and then in every mode
  • the new test passed 20/20 in debug and 20/20 in release
  • full lib suite (4 threads, skipping descriptor::tests::views_die_with_their_resource which crashes on main too) gives main 338 passed, 5 failed, 23 ignored, and this PR 321 passed, 5 failed, 23 ignored both unset and =1. Same 5 failures, no shared test changed status. The difference is 18 tests that only exist on main plus the new one here
  • clippy --all-targets shows the same warnings as main

The watch failure is already on main and isn't from this PR. It passes alone (20/20). Run right after bits_go_at_every_view in the same process it fails every time on main and here. A stale VIEWS bit is left on an address that VirtualAlloc hands out again, so refused_as_view makes writes() return None even though GetWriteWatch would have answered. I don't know if Wine reuses addresses the same way.

AI-assisted: yes

**@⁠Kal0s-design** on GitHub · 2026-12-03 19:39 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/312#issuecomment-7390022580) Tested e7c3699 on Windows 11 natively (MSVC, toolchain 1.98.1), so the write watch is the real GetWriteWatch with the reset flag, not Wine. CPU-only, victory-gpu lib tests. Reading the change I didn't find a problem. AheadAsking::hold checks for overlap and inserts the union under the same ASKING lock, so two overlapping holders can't both get in, and hold_all and a scoped hold wait for each other. Lock order is AHEAD_BATCH then ASKING then the journal, and ask_once passes held=true so it never takes AHEAD_BATCH. The guards outlive journal publication and get dropped on the early kept return and on unwind. The reset only ever covers a run span or half of one, which is inside the claim, and the gap pages inside a run are part of the span. With the variable unset it's the same hold_all and publication as before. One thing worth knowing is that the existing tests never reach the scoped branch. I added a temporary print there and nothing in the suite hit it with the variable set, since the only standalone ask_ahead in the tests passes a single range. So I wrote a few throwaway tests locally (not pushed). Disjoint holders and a writes-style hold in the gap between two runs get through, overlapping ones block until drop, hold_all and a scoped hold block each other both ways, and a panic while holding releases the ranges. On two small write-watched allocations, ask_ahead over three ranges of the first one answers the first one's written page from the journal and leaves a write in the second allocation for writes() to find. Three threads mixing ask_ahead, writes and ask_once finished without hanging. All of these passed with the variable set, and the last two also with it unset. Also, because of AHEAD_BATCH two standalone batches still run one at a time even when they don't overlap. The doc comment says so, I'm just mentioning it in case the title reads like they run in parallel. Results - watch:: tests in debug and release, unset, =0 and =1, all pass except the_rest_of_the_one_asking_has_a_number_of_its_own, which fails now and then in every mode - the new test passed 20/20 in debug and 20/20 in release - full lib suite (4 threads, skipping descriptor::tests::views_die_with_their_resource which crashes on main too) gives main 338 passed, 5 failed, 23 ignored, and this PR 321 passed, 5 failed, 23 ignored both unset and =1. Same 5 failures, no shared test changed status. The difference is 18 tests that only exist on main plus the new one here - clippy --all-targets shows the same warnings as main The watch failure is already on main and isn't from this PR. It passes alone (20/20). Run right after bits_go_at_every_view in the same process it fails every time on main and here. A stale VIEWS bit is left on an address that VirtualAlloc hands out again, so refused_as_view makes writes() return None even though GetWriteWatch would have answered. I don't know if Wine reuses addresses the same way. AI-assisted: yes
Author
Owner

@⁠tommiehansen on GitHub · 2026-12-03 19:53 UTC · original

Sorted Disjoint AskingRanges & Zero-Sort Fast Path (c105943)

Merged origin/main (45591b0) cleanly with zero conflicts and extracted the interval hold/run logic into pure-Rust crates/victory-gpu/src/watch/asking_ranges.rs while keeping VICTORY_ASK_AHEAD_SCOPED, AHEAD_BATCH, and Asking::hold_all() behavior intact.

Technical changes

  • Sorted, pairwise-disjoint AskingRanges table: Replaces the linear Vec<(usize, usize)> scans and O(H log U) retain(binary_search) with O(log H) partition_point single-range overlap checks, O(H + U) two-pointer batch overlap/merge sweeps, and a zero-alloc in-place O(H + U) two-pointer remove_batch sweep.
  • Zero-sort batch normalization fast path (normalize_batch): When ask_ahead_held supplies already-sorted disjoint run spans (separated by AHEAD_GAP), normalize_batch returns the vector in place without sorting or reallocating union.

macOS ARM64 CPU Benchmark Results (rustc -O, A/B/B/A 8-block median, direct production asking_ranges.rs)

Scenario Previous PR #312 (Vec) Updated (AskingRanges) Delta
Single hold + drop gap check (H=256) 151.6 ns 72.2 ns -52.42%
Single overlap hit near tail (H=256) 66.2 ns 4.1 ns -93.82%
Scoped batch hold + drop (U=256, H=16) 3,038.4 ns 668.2 ns -78.01%

Multi-threaded disjoint contention check (4 threads x 4,000 non-overlapping hold/drop calls while an ahead batch holds 128 spans): hold_all() took 3,411 us (4 blocked workers) vs scoped AskingRanges 2,534 us (0 blocked workers).

Verification & Reproduction

  • Native unit & randomized brute-force oracle tests (macOS ARM64):
    rustc --edition 2024 --test crates/victory-gpu/src/watch/asking_ranges.rs -o /tmp/test_asking_ranges && /tmp/test_asking_ranges (4 passed, 0 failed, 512 randomized single/batch hold-overlap-remove steps).
  • Windows cross-target check:
    cargo check -p victory-gpu --lib --target x86_64-pc-windows-msvc --features blake3/pure and --all-targets --features blake3/pure,diagnostics (0 errors, 0 warnings, check-only libmimalloc-sys shim), plus cargo --offline xtask policy --staged (2 files ok) and xtask -- switches (0 new errors).
  • Known limitations: Benchmarks ran on macOS ARM64 CPU-only; live Windows GetWriteWatch contention and frame-time impact require external Windows/AMD hardware testing.
**@⁠tommiehansen** on GitHub · 2026-12-03 19:53 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/312#issuecomment-7390382669) ### Sorted Disjoint `AskingRanges` & Zero-Sort Fast Path (`c105943`) Merged `origin/main` (`45591b0`) cleanly with zero conflicts and extracted the interval hold/run logic into pure-Rust `crates/victory-gpu/src/watch/asking_ranges.rs` while keeping `VICTORY_ASK_AHEAD_SCOPED`, `AHEAD_BATCH`, and `Asking::hold_all()` behavior intact. #### Technical changes - **Sorted, pairwise-disjoint `AskingRanges` table:** Replaces the linear `Vec<(usize, usize)>` scans and `O(H log U)` `retain(binary_search)` with `O(log H)` `partition_point` single-range overlap checks, `O(H + U)` two-pointer batch overlap/merge sweeps, and a zero-alloc in-place `O(H + U)` two-pointer `remove_batch` sweep. - **Zero-sort batch normalization fast path (`normalize_batch`):** When `ask_ahead_held` supplies already-sorted disjoint run spans (separated by `AHEAD_GAP`), `normalize_batch` returns the vector in place without sorting or reallocating `union`. #### macOS ARM64 CPU Benchmark Results (`rustc -O`, A/B/B/A 8-block median, direct production `asking_ranges.rs`) | Scenario | Previous PR #312 (`Vec`) | Updated (`AskingRanges`) | Delta | | --- | ---: | ---: | ---: | | Single `hold + drop` gap check (`H=256`) | 151.6 ns | 72.2 ns | **-52.42%** | | Single overlap hit near tail (`H=256`) | 66.2 ns | 4.1 ns | **-93.82%** | | Scoped batch `hold + drop` (`U=256`, `H=16`) | 3,038.4 ns | 668.2 ns | **-78.01%** | Multi-threaded disjoint contention check (4 threads x 4,000 non-overlapping `hold/drop` calls while an ahead batch holds 128 spans): `hold_all()` took **3,411 us** (4 blocked workers) vs scoped `AskingRanges` **2,534 us** (0 blocked workers). #### Verification & Reproduction - **Native unit & randomized brute-force oracle tests (macOS ARM64):** `rustc --edition 2024 --test crates/victory-gpu/src/watch/asking_ranges.rs -o /tmp/test_asking_ranges && /tmp/test_asking_ranges` (4 passed, 0 failed, 512 randomized single/batch hold-overlap-remove steps). - **Windows cross-target check:** `cargo check -p victory-gpu --lib --target x86_64-pc-windows-msvc --features blake3/pure` and `--all-targets --features blake3/pure,diagnostics` (0 errors, 0 warnings, check-only `libmimalloc-sys` shim), plus `cargo --offline xtask policy --staged` (2 files ok) and `xtask -- switches` (0 new errors). - **Known limitations:** Benchmarks ran on macOS ARM64 CPU-only; live Windows `GetWriteWatch` contention and frame-time impact require external Windows/AMD hardware testing.
Author
Owner

@⁠Kal0s-design on GitHub · 2026-12-03 20:21 UTC · original

Re-tested at c105943 on Windows 11 natively (MSVC), so real GetWriteWatch again, CPU-only, victory-gpu lib tests.

The thing I wanted to check first was whether the sorted table could let one holder's drop take away another holder's protection. It can't as far as I can tell. insert_range and insert_batch never merge entries in the table, they only insert, so each holder's ranges stay as separate entries. Live entries are non-empty and pairwise disjoint (the overlap check and the insert happen under the same lock), so no two holders can own an equal entry and removing by exact match only ever hits the owner's. Touching holders like [a,b) and [b,c) are both allowed, same half-open rule as the old overlaps_asking.

normalize_batch does verify its input rather than trusting it. The fast path needs every range non-empty and a strict gap between neighbours, so touching, overlapping, empty or unsorted input goes to the sort and merge. That matters a bit because the run spans aren't always separated by AHEAD_GAP. When a run is cut by AHEAD_MAX the next run can start before the previous one ends, and those spans get merged there, which is fine.

Two small behaviour differences, both harmless as far as I can see. An empty Asking::hold is no longer stored (before, an entry (a,a) could make an ahead batch whose union contained a wait), and build_ahead_runs now uses saturating_add for the gap.

What I ran locally (not pushed)

  • a randomized differential test against a reference that keeps each holder's ranges separately, like the old Vec. 400k steps in total, mixing single holds and batches, with empty, reversed, duplicate, touching and overlapping input, drops in random order, and some runs placed right under usize::MAX. Every step compares the table, overlaps_range and overlaps_batch with the reference and checks that normalize_batch keeps the same pages. No mismatch
  • build_ahead_runs against the previous inline loop on 100k random inputs, same output
  • the real ASKING statics: a single hold, a batch that touches it on both sides and an empty hold. After dropping the neighbours the batch still blocks a hold inside it, and once everything is dropped a hold over the whole area goes through
  • the same real write-watched memory checks as last time (two small allocations, ask_ahead over three ranges of the first, writes in a gap page and in the second allocation, three threads mixing ask_ahead, writes and ask_once with a timeout). A temporary print confirmed the scoped branch was taken. Passed unset, =0 and =1, repeated several times

Results

  • watch:: in debug and release, unset and =1, all pass except the_rest_of_the_one_asking_has_a_number_of_its_own when unset, the same flaky one from main I mentioned before
  • the four new asking_ranges tests 20/20 in debug and 20/20 in release
  • full lib suite (4 threads, skipping descriptor::tests::views_die_with_their_resource) gives 333 passed, 5 failed, 23 ignored both unset and =1. Main gives 338/5/23 with the same 5 failures. The difference is the 9 tests main has after your merge base and the 4 new ones here
  • clippy --all-targets shows the same warnings as main, nothing in the new file

I didn't measure timings, so nothing to add on the performance side.

AI-assisted: yes

**@⁠Kal0s-design** on GitHub · 2026-12-03 20:21 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/312#issuecomment-7391113679) Re-tested at c105943 on Windows 11 natively (MSVC), so real GetWriteWatch again, CPU-only, victory-gpu lib tests. The thing I wanted to check first was whether the sorted table could let one holder's drop take away another holder's protection. It can't as far as I can tell. insert_range and insert_batch never merge entries in the table, they only insert, so each holder's ranges stay as separate entries. Live entries are non-empty and pairwise disjoint (the overlap check and the insert happen under the same lock), so no two holders can own an equal entry and removing by exact match only ever hits the owner's. Touching holders like [a,b) and [b,c) are both allowed, same half-open rule as the old overlaps_asking. normalize_batch does verify its input rather than trusting it. The fast path needs every range non-empty and a strict gap between neighbours, so touching, overlapping, empty or unsorted input goes to the sort and merge. That matters a bit because the run spans aren't always separated by AHEAD_GAP. When a run is cut by AHEAD_MAX the next run can start before the previous one ends, and those spans get merged there, which is fine. Two small behaviour differences, both harmless as far as I can see. An empty Asking::hold is no longer stored (before, an entry (a,a) could make an ahead batch whose union contained a wait), and build_ahead_runs now uses saturating_add for the gap. What I ran locally (not pushed) - a randomized differential test against a reference that keeps each holder's ranges separately, like the old Vec. 400k steps in total, mixing single holds and batches, with empty, reversed, duplicate, touching and overlapping input, drops in random order, and some runs placed right under usize::MAX. Every step compares the table, overlaps_range and overlaps_batch with the reference and checks that normalize_batch keeps the same pages. No mismatch - build_ahead_runs against the previous inline loop on 100k random inputs, same output - the real ASKING statics: a single hold, a batch that touches it on both sides and an empty hold. After dropping the neighbours the batch still blocks a hold inside it, and once everything is dropped a hold over the whole area goes through - the same real write-watched memory checks as last time (two small allocations, ask_ahead over three ranges of the first, writes in a gap page and in the second allocation, three threads mixing ask_ahead, writes and ask_once with a timeout). A temporary print confirmed the scoped branch was taken. Passed unset, =0 and =1, repeated several times Results - watch:: in debug and release, unset and =1, all pass except the_rest_of_the_one_asking_has_a_number_of_its_own when unset, the same flaky one from main I mentioned before - the four new asking_ranges tests 20/20 in debug and 20/20 in release - full lib suite (4 threads, skipping descriptor::tests::views_die_with_their_resource) gives 333 passed, 5 failed, 23 ignored both unset and =1. Main gives 338/5/23 with the same 5 failures. The difference is the 9 tests main has after your merge base and the 4 new ones here - clippy --all-targets shows the same warnings as main, nothing in the new file I didn't measure timings, so nothing to add on the performance side. AI-assisted: yes
Author
Owner

@⁠Luxuride on GitHub · 2026-12-04 12:09 UTC · original

Porting the overlap check to a sorted disjoint set with overlaps_batch/insert_batch and four unit tests is the right shape, and scoping the hold to the queried runs is the right idea. The boring part is missing.

What I checked:

  • The deadlock argument is unwritten. crates/victory-gpu/src/watch.rs:595 (static AHEAD_BATCH: Mutex<()>) serialises scoped batches, and AheadAsking::hold still blocks on the ASKING condvar while that mutex is held (watch.rs:612-625). It is deadlock-free today only because the whole-submission path never takes AHEAD_BATCH. That is one refactor away from a hang. Put that invariant in a comment at watch.rs:595; it is the single most valuable line in the PR.
  • Nothing tests the interleaving. crates/victory-gpu/src/watch.rs:735-742: the double journal().kept check is correct, but the second one returns while a scoped AheadAsking guard is alive — the guard's Drop takes ASKING, notifies, and then the function returns. The empty-publication path at watch.rs:1204 (normalize_batch) covers it; no test pins it. One test where a whole-submission publish lands during a scoped wait would nail it down.
  • The perf claim is unmeasured. "O(log n) overlap" is plausible — the real win is deleting a linear scan over a possibly large held set — but the PR never says how big that set gets. One line of instrumentation in the PR body would be enough.
  • VICTORY_ASK_AHEAD_SCOPED is in docs/SETTINGS.md:33 but not in run.conf.default, unlike VICTORY_LATE_FENCE and VICTORY_BAKE_SOURCES_ONLY. Same gap as the other experiment-shaped PRs in this batch.

56 commits behind, merges clean (AHEAD_BATCH and the refresh-front work do not touch the same files). Comment on the mutex, one interleaving test, one run.conf.default row, and it is ready.

**@⁠Luxuride** on GitHub · 2026-12-04 12:09 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/312#issuecomment-7411055138) Porting the overlap check to a sorted disjoint set with `overlaps_batch`/`insert_batch` and four unit tests is the right shape, and scoping the hold to the queried runs is the right idea. The boring part is missing. What I checked: - **The deadlock argument is unwritten.** `crates/victory-gpu/src/watch.rs:595` (`static AHEAD_BATCH: Mutex<()>`) serialises scoped batches, and `AheadAsking::hold` still blocks on the `ASKING` condvar while that mutex is held (`watch.rs:612-625`). It is deadlock-free **today** only because the whole-submission path never takes `AHEAD_BATCH`. That is one refactor away from a hang. Put that invariant in a comment at `watch.rs:595`; it is the single most valuable line in the PR. - **Nothing tests the interleaving.** `crates/victory-gpu/src/watch.rs:735-742`: the double `journal().kept` check is correct, but the second one returns while a scoped `AheadAsking` guard is alive — the guard's `Drop` takes `ASKING`, notifies, and then the function returns. The empty-publication path at `watch.rs:1204` (`normalize_batch`) covers it; no test pins it. One test where a whole-submission publish lands during a scoped wait would nail it down. - **The perf claim is unmeasured.** "O(log n) overlap" is plausible — the real win is deleting a linear scan over a possibly large held set — but the PR never says how big that set gets. One line of instrumentation in the PR body would be enough. - `VICTORY_ASK_AHEAD_SCOPED` is in `docs/SETTINGS.md:33` but not in `run.conf.default`, unlike `VICTORY_LATE_FENCE` and `VICTORY_BAKE_SOURCES_ONLY`. Same gap as the other experiment-shaped PRs in this batch. 56 commits behind, merges clean (`AHEAD_BATCH` and the refresh-front work do not touch the same files). Comment on the mutex, one interleaving test, one `run.conf.default` row, and it is ready.
github-bot changed title from watch: scope standalone ahead queries to covered page ranges to perf(gpu): scope standalone ahead queries to covered page ranges 2026-12-04 22:20:14 +00:00
Author
Owner

@⁠tommiehansen on GitHub · 2026-12-05 10:19 UTC · original

Thanks @⁠Luxuride for identifying the lock-order and interleaving coverage gap. 31a6bd5 documents AHEAD_BATCH/ASKING ordering and adds the whole-submission publication regression during a scoped wait. MSVC compilation and targeted tests passed, including on the refreshed head. Gameplay benefit remains unmeasured.

**@⁠tommiehansen** on GitHub · 2026-12-05 10:19 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/312#issuecomment-7436366699) Thanks @⁠Luxuride for identifying the lock-order and interleaving coverage gap. [31a6bd5](https://github.com/tommiehansen/VIctory-xmem/commit/31a6bd57c590d6e7758baf0d1b6158c82de258d5) documents AHEAD_BATCH/ASKING ordering and adds the whole-submission publication regression during a scoped wait. MSVC compilation and targeted tests passed, including on the [refreshed head](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47466412636/job/145504218275). Gameplay benefit remains unmeasured.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/312/head:github-bot/gh-312'
git switch 'github-bot/gh-312'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-312'
git switch 'github-bot/gh-312'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-312'
git switch 'github-bot/gh-312'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-312'
git switch 'main'
git merge --squash 'github-bot/gh-312'
git switch 'main'
git merge --ff-only 'github-bot/gh-312'
git switch 'main'
git merge 'github-bot/gh-312'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.