perf(watch): overlap guard_ahead with card_steps and deduplicate copy-span scans #291

Closed
github-bot wants to merge 0 commits from github-bot/gh-291 into main AGit
Owner

@⁠leixner on GitHub · 2026-12-01 10:25 UTC · original
leixner:perf/overlap-guard-and-dedup-spans → main · +101 −45 · 2 files · 67 commits · closed without merging

Summary

Reduces submitting-thread write-watch overhead when VICTORY_ASK_FIRST=1 by overlapping guard_ahead with card_steps, eliminating duplicate copy-span scans per submission, and avoiding unnecessary lock acquisitions in ask_more.

Changes

  1. Overlap guard_ahead with card_steps (crates/victory-gpu/src/watch.rs, crates/victory-gpu/src/host.rs)
    • Extend watch::ask_first to accept both ranges (asked_ahead) and guarded (guarded_copy) so the victory-ask worker runs ask_once followed by guard_ahead while the submitting thread runs card_steps.
    • AskedFirst::wait() returns whether the background round succeeded (bool). When it succeeds and no flight wait or sweep invalidated it:
      • If own did not add a list, skip both ask_more and guard_ahead on the submitting thread.
      • If own added a list, run ask_more and only guard own.list().
  2. Eliminate redundant copy-span scans (crates/victory-gpu/src/host.rs)
    • Factor Batch::extend_copy_spans(&mut self, list: &HostList) out of Batch::copy_spans.
    • When VICTORY_ASK_FIRST=1, scan runs once before ask_first to populate batch.spans and derive both ranges and guarded, then only call batch.extend_copy_spans(own.list()) after card_steps if own is present (avoiding 2 redundant full scans of all ~200 lists per submission).
  3. Skip published() lock for covered ranges in ask_more (crates/victory-gpu/src/watch.rs)
    • Merge held ranges and check coverage via binary search (interval_contains / partition_point) before calling lock-acquiring published().
    • Add unit test watch::ask_holds::interval_contains_matches_sorted_merged_ranges.

Verification

  • cargo test -p victory-gpu --lib watch — 52 passed, 0 failed.
  • cargo xtask policy — 293 files ok.
  • Gameplay A/B on Ryzen 7 5700X + RTX 3070 8 GB (Xbox Series X @ 1440p, VICTORY_WIDE_THREADS=8, 246 gameplay windows, 0 errors):
Metric (gameplay med / p90) Baseline (main) This PR Delta
Write watch (asking the write watch) 7.8 / 10.1 ms 6.5 / 8.2 ms -17% med / -19% p90
Finding what to ask 1.4 / 1.7 ms 1.0 / 1.3 ms -29% med / -24% p90
ask_more follow-ups / frame 6.5 / 7.3 4.5 / 5.2 -31% med / -29% p90
GPU idle behind submitting thread (p90) 26.3 ms 18.2 ms -31% p90 spikes
**@⁠leixner** on GitHub · 2026-12-01 10:25 UTC · [original](https://github.com/readmet3xt-lab/foxhound/pull/291) `leixner:perf/overlap-guard-and-dedup-spans` → `main` · +101 −45 · 2 files · 67 commits · closed without merging ## Summary Reduces submitting-thread write-watch overhead when `VICTORY_ASK_FIRST=1` by overlapping `guard_ahead` with `card_steps`, eliminating duplicate copy-span scans per submission, and avoiding unnecessary lock acquisitions in `ask_more`. ### Changes 1. **Overlap `guard_ahead` with `card_steps`** (`crates/victory-gpu/src/watch.rs`, `crates/victory-gpu/src/host.rs`) - Extend `watch::ask_first` to accept both `ranges` (`asked_ahead`) and `guarded` (`guarded_copy`) so the `victory-ask` worker runs `ask_once` followed by `guard_ahead` while the submitting thread runs `card_steps`. - `AskedFirst::wait()` returns whether the background round succeeded (`bool`). When it succeeds and no flight wait or sweep invalidated it: - If `own` did not add a list, skip both `ask_more` and `guard_ahead` on the submitting thread. - If `own` added a list, run `ask_more` and only guard `own.list()`. 2. **Eliminate redundant copy-span scans** (`crates/victory-gpu/src/host.rs`) - Factor `Batch::extend_copy_spans(&mut self, list: &HostList)` out of `Batch::copy_spans`. - When `VICTORY_ASK_FIRST=1`, scan `runs` once before `ask_first` to populate `batch.spans` and derive both `ranges` and `guarded`, then only call `batch.extend_copy_spans(own.list())` after `card_steps` if `own` is present (avoiding 2 redundant full scans of all ~200 lists per submission). 3. **Skip `published()` lock for covered ranges in `ask_more`** (`crates/victory-gpu/src/watch.rs`) - Merge `held` ranges and check coverage via binary search (`interval_contains` / `partition_point`) before calling lock-acquiring `published()`. - Add unit test `watch::ask_holds::interval_contains_matches_sorted_merged_ranges`. ## Verification - `cargo test -p victory-gpu --lib watch` — **52 passed, 0 failed**. - `cargo xtask policy` — **293 files ok**. - Gameplay A/B on Ryzen 7 5700X + RTX 3070 8 GB (Xbox Series X @ 1440p, `VICTORY_WIDE_THREADS=8`, 246 gameplay windows, 0 errors): | Metric (gameplay med / p90) | Baseline (`main`) | This PR | Delta | | --- | --- | --- | --- | | Write watch (`asking the write watch`) | 7.8 / 10.1 ms | **6.5 / 8.2 ms** | **-17% med / -19% p90** | | Finding what to ask | 1.4 / 1.7 ms | **1.0 / 1.3 ms** | **-29% med / -24% p90** | | `ask_more` follow-ups / frame | 6.5 / 7.3 | **4.5 / 5.2** | **-31% med / -29% p90** | | GPU idle behind submitting thread (p90) | 26.3 ms | **18.2 ms** | **-31% p90 spikes** |
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 10:28:02 +00:00
Author
Owner

@⁠Aniseto on GitHub · 2026-12-01 10:32 UTC · original

Ran the watch test group at 9848925 on an NVIDIA Blackwell desktop part with 16 GB of VRAM.

Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB, mesh shaders) driver 32.0.16.2140 (621.40), Intel Core i5-12400F, 64 GB RAM, rustc 1.98.1 (48a229cea 2026-09-01), MSVC 14.44.35207, debug build, detached worktree at the exact PR head, own CARGO_TARGET_DIR, no local patches.

cargo test -q -p victory-gpu --lib watch -- --test-threads=1
52 passed; 0 failed; 0 ignored; 460 filtered out      (exit 0)

All 52 watch tests pass here, the same count as the description, including ask_holds::interval_contains_matches_sorted_merged_ranges. The description of #277 notes that this group fails randomly on its host with and without that other change; it passed here in this single run, so no claim about repeatability is made.

Not tested: the full workspace suite, a title run, a paired frame-time A/B, Wine, AMD adapters, release profile, game data.

AI-assisted (OpenCode), model: MiMo-V2.6-Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.

**@⁠Aniseto** on GitHub · 2026-12-01 10:32 UTC · [original](https://github.com/readmet3xt-lab/foxhound/pull/291#issuecomment-7308344000) Ran the `watch` test group at `9848925` on an NVIDIA Blackwell desktop part with 16 GB of VRAM. Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB, mesh shaders) driver 32.0.16.2140 (621.40), Intel Core i5-12400F, 64 GB RAM, rustc 1.98.1 (48a229cea 2026-09-01), MSVC 14.44.35207, debug build, detached worktree at the exact PR head, own `CARGO_TARGET_DIR`, no local patches. ``` cargo test -q -p victory-gpu --lib watch -- --test-threads=1 52 passed; 0 failed; 0 ignored; 460 filtered out (exit 0) ``` All 52 `watch` tests pass here, the same count as the description, including `ask_holds::interval_contains_matches_sorted_merged_ranges`. The description of #277 notes that this group fails randomly on its host with and without that other change; it passed here in this single run, so no claim about repeatability is made. Not tested: the full workspace suite, a title run, a paired frame-time A/B, Wine, AMD adapters, release profile, game data. AI-assisted (OpenCode), model: **MiMo-V2.6-Flash Free** - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.
Author
Owner

@⁠readmet3xt-lab on GitHub · 2026-12-01 10:50 UTC · original

Not merged for now, for a merge reason, not a quality one: the batch under test already carries #109, which does the first part of this differently (the view memory is guarded beside the asking, on a helper thread, and the submitting thread still calls guard_ahead and finds the ranges published). The two change the same lines of watch::ask_first and of the submission in host.rs, and joining them by hand would mean choosing between the two designs in code that decides whether a write is seen.

What would be welcome once that batch is on main: this pull request rebased on it, keeping parts 2 and 3 (one scan of the copy spans, and the check of held ranges before published()), and part 1 only where it still saves something over #109. The lint check of this branch on main passes.

**@⁠readmet3xt-lab** on GitHub · 2026-12-01 10:50 UTC · [original](https://github.com/readmet3xt-lab/foxhound/pull/291#issuecomment-7308796501) Not merged for now, for a merge reason, not a quality one: the batch under test already carries #109, which does the first part of this differently (the view memory is guarded beside the asking, on a helper thread, and the submitting thread still calls `guard_ahead` and finds the ranges published). The two change the same lines of `watch::ask_first` and of the submission in `host.rs`, and joining them by hand would mean choosing between the two designs in code that decides whether a write is seen. What would be welcome once that batch is on main: this pull request rebased on it, keeping parts 2 and 3 (one scan of the copy spans, and the check of held ranges before `published()`), and part 1 only where it still saves something over #109. The lint check of this branch on main passes.
Author
Owner

@⁠leixner on GitHub · 2026-12-01 10:59 UTC · original

Sounds good — thanks for the clear breakdown! Once that batch with #109 lands on main, I'll rebase this PR onto it keeping parts 2 and 3 (single copy-span scan + held-range check before published()), and re-measure whether any of part 1 is still additive on top of #109.

**@⁠leixner** on GitHub · 2026-12-01 10:59 UTC · [original](https://github.com/readmet3xt-lab/foxhound/pull/291#issuecomment-7309001863) Sounds good — thanks for the clear breakdown! Once that batch with #109 lands on `main`, I'll rebase this PR onto it keeping parts 2 and 3 (single copy-span scan + held-range check before `published()`), and re-measure whether any of part 1 is still additive on top of #109.
Author
Owner

@⁠FIJI1299 on GitHub · 2026-12-01 11:11 UTC · original

Community Validation — PR #291 (9848925)

Verified locally on Windows 11 with an RTX 5070 (perf(watch): overlap guard_ahead with card_steps and deduplicate copy-span scans).

Environment

  • Commit: 9848925d792e1758337008342ce34a42bf0f1a7a (pr-291)
  • GPU: NVIDIA GeForce RTX 5070 (12 GB)
  • Driver: 621.40.0 (stock, no OC/tweaks)
  • OS: Windows 11 26H2 (10.0.26300) — HAGS enabled
  • System RAM: 32 GB

Results

  • cargo clippy --workspace --all-targets --locked -- -D warnings: Passed cleanly (0 warnings, 0 errors).
  • cargo test --workspace --locked: Passed across the entire workspace (1,116 passed, 0 failed, 48 ignored), including all 475 tests in victory-gpu (host.rs / watch.rs).
victory          : 14 passed; 0 failed
victory-formats  : 43 passed; 0 failed; 5 ignored
victory-gpu      : 475 passed; 0 failed; 37 ignored
victory-hle      : 178 passed; 0 failed; 2 ignored
victory-loader   : 44 passed; 0 failed
victory-pe       : 36 passed; 0 failed
victory-shader   : 291 passed; 0 failed; 4 ignored
(all remaining crates & integration tests: 35 passed; 0 failed)

— Compiled with Gemini

**@⁠FIJI1299** on GitHub · 2026-12-01 11:11 UTC · [original](https://github.com/readmet3xt-lab/foxhound/pull/291#issuecomment-7309296526) ### Community Validation — PR #291 (`9848925`) Verified locally on Windows 11 with an RTX 5070 (`perf(watch): overlap guard_ahead with card_steps and deduplicate copy-span scans`). ### Environment - **Commit:** `9848925d792e1758337008342ce34a42bf0f1a7a` (`pr-291`) - **GPU:** NVIDIA GeForce RTX 5070 (12 GB) - **Driver:** `621.40.0` (stock, no OC/tweaks) - **OS:** Windows 11 26H2 (`10.0.26300`) — HAGS enabled - **System RAM:** 32 GB ### Results - **`cargo clippy --workspace --all-targets --locked -- -D warnings`:** Passed cleanly (0 warnings, 0 errors). - **`cargo test --workspace --locked`:** Passed across the entire workspace (**1,116 passed, 0 failed, 48 ignored**), including all **475** tests in `victory-gpu` (`host.rs` / `watch.rs`). ```text victory : 14 passed; 0 failed victory-formats : 43 passed; 0 failed; 5 ignored victory-gpu : 475 passed; 0 failed; 37 ignored victory-hle : 178 passed; 0 failed; 2 ignored victory-loader : 44 passed; 0 failed victory-pe : 36 passed; 0 failed victory-shader : 291 passed; 0 failed; 4 ignored (all remaining crates & integration tests: 35 passed; 0 failed) ``` --- *— Compiled with Gemini*
Author
Owner

@⁠readmet3xt-lab on GitHub · 2026-12-01 12:16 UTC · original

An update: parts 2 and 3 are now on the batch for the release after next, ported over #109 as one commit with you as its author (one walk of the copy steps where the asking is begun first; the held ranges joined and searched before published()'s locks). Lint in both feature sets and the whole test suite pass.

Three things differ from this branch, each for safety, and you may want them in your own version:

  1. The ranges given to guard_ahead stay each step's own range. Here they came from batch.spans, which is a copy's whole span (the hull of all its refreshes), so more view memory than is refreshed would be made read-only.
  2. The copies of the list of card steps are put first in the spans, as one walk of all lists has them; appended last, the pass over stale copies works through them in another order under its budget.
  3. The other lists are walked again if they do not have as many steps as at the first walk; otherwise only the card-steps list is walked.

A test shows the split walk gives the same spans, in the same order, as one walk. Part 1 (the guarding skipped on the submitting thread when the round on the asking thread succeeded) is not in yet; it will go in behind a switch, on top of #109's form, and be measured.

**@⁠readmet3xt-lab** on GitHub · 2026-12-01 12:16 UTC · [original](https://github.com/readmet3xt-lab/foxhound/pull/291#issuecomment-7310899920) An update: parts 2 and 3 are now on the batch for the release after next, ported over #109 as one commit with you as its author (one walk of the copy steps where the asking is begun first; the held ranges joined and searched before `published()`'s locks). Lint in both feature sets and the whole test suite pass. Three things differ from this branch, each for safety, and you may want them in your own version: 1. The ranges given to `guard_ahead` stay each step's own range. Here they came from `batch.spans`, which is a copy's whole span (the hull of all its refreshes), so more view memory than is refreshed would be made read-only. 2. The copies of the list of card steps are put first in the spans, as one walk of all lists has them; appended last, the pass over stale copies works through them in another order under its budget. 3. The other lists are walked again if they do not have as many steps as at the first walk; otherwise only the card-steps list is walked. A test shows the split walk gives the same spans, in the same order, as one walk. Part 1 (the guarding skipped on the submitting thread when the round on the asking thread succeeded) is not in yet; it will go in behind a switch, on top of #109's form, and be measured.
github-bot closed this pull request 2026-12-02 07:54:51 +00:00

Pull request closed

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