GPU: collect tracked page runs without temporary trees #3387

Open
github-bot wants to merge 1 commit from github-bot/gh-3387 into main AGit
Owner

@⁠Desamodeth on GitHub · 2026-11-26 21:23 UTC · original
Desamodeth:perf/watch-runtime-page-runs → main · +34 −3 · 1 files · 1 commits · open

The fallback in watch::runtime_pages inserted each 64 KiB page into a temporary BTreeSet of eligible or foreign pages, then took their difference. Even a range consisting entirely of ordinary committed memory allocated tree nodes to return an empty vector. This follows borosf's measurement of the cost of building those sets. Original finding · Coordination claim.

Walk the VirtualQuery regions in address order. When a foreign region appears, emit the eligible run before its first page and resume after its last page. A 4 KiB foreign region therefore excludes its entire overlapping 64 KiB page. The final run ends at the last successfully queried region. The Windows queries, classification predicate, write-watched fast path and caller are unchanged.

CPU measurements

Median µs per call to runtime_pages, base 63bcca43 vs this patch. The range of medians is from two runs in opposite order.

Synthetic Windows mapping Base Patched Heap allocations per call, base → patched
64 MiB ordinary private committed memory, views disabled 22.9–24.8 1.4–1.5 171 → 0
64 MiB mixed reservation, views enabled 110.5–113.5 83.8–86.3 177 → 7
64 MiB write-watched allocation, views disabled 13.0–13.4 13.1–13.4 1 → 1

Windows x64, Ryzen 7 9800X3D, rustc 1.98.1, -C opt-level=3. The isolated benchmark called the old and new functions on the same native VirtualAlloc mapping, alternating order and taking 21 samples per variant after two warm-ups. For the mixed case, reserve 64 MiB, then commit one 4 KiB block at offset i * 65536 + 4096 for i = 1, 33, 65, …. Both versions return the same 992 page numbers. Allocation counts came from a separate counting-allocator build. These measurements cover page classification only.

Correctness

  • Added a Windows regression for an ordinary 4 KiB committed block inside a 64 KiB page. Checks both sides of the block, partially covered end pages and both values of views.
  • Compared both implementations with an independent page-membership oracle on 3,200 range/mode combinations over a real mixed Windows reservation.
  • All 16 victory-gpu watch tests passed on Windows. Workspace Clippy passed for all targets with default and all features, with warnings denied. cargo xtask policy passed (191 files).

AI-assisted with Codex. No game data or GPU used for local verification.

**@⁠Desamodeth** on GitHub · 2026-11-26 21:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/3387) `Desamodeth:perf/watch-runtime-page-runs` → `main` · +34 −3 · 1 files · 1 commits · open The fallback in `watch::runtime_pages` inserted each 64 KiB page into a temporary `BTreeSet` of eligible or foreign pages, then took their difference. Even a range consisting entirely of ordinary committed memory allocated tree nodes to return an empty vector. This follows borosf's measurement of the cost of building those sets. [Original finding](https://git.gtahub.st/github/Marvisak--VIctory/issues/1633) · [Coordination claim](https://git.gtahub.st/github/Marvisak--VIctory/issues/1633). Walk the `VirtualQuery` regions in address order. When a foreign region appears, emit the eligible run before its first page and resume after its last page. A 4 KiB foreign region therefore excludes its entire overlapping 64 KiB page. The final run ends at the last successfully queried region. The Windows queries, classification predicate, write-watched fast path and caller are unchanged. ### CPU measurements Median µs per call to `runtime_pages`, base `63bcca43` vs this patch. The range of medians is from two runs in opposite order. | Synthetic Windows mapping | Base | Patched | Heap allocations per call, base → patched | |---|---:|---:|---:| | 64 MiB ordinary private committed memory, views disabled | 22.9–24.8 | 1.4–1.5 | 171 → 0 | | 64 MiB mixed reservation, views enabled | 110.5–113.5 | 83.8–86.3 | 177 → 7 | | 64 MiB write-watched allocation, views disabled | 13.0–13.4 | 13.1–13.4 | 1 → 1 | Windows x64, Ryzen 7 9800X3D, rustc 1.98.1, `-C opt-level=3`. The isolated benchmark called the old and new functions on the same native `VirtualAlloc` mapping, alternating order and taking 21 samples per variant after two warm-ups. For the mixed case, reserve 64 MiB, then commit one 4 KiB block at offset `i * 65536 + 4096` for `i = 1, 33, 65, …`. Both versions return the same 992 page numbers. Allocation counts came from a separate counting-allocator build. These measurements cover page classification only. ### Correctness - Added a Windows regression for an ordinary 4 KiB committed block inside a 64 KiB page. Checks both sides of the block, partially covered end pages and both values of `views`. - Compared both implementations with an independent page-membership oracle on 3,200 range/mode combinations over a real mixed Windows reservation. - All 16 `victory-gpu` watch tests passed on Windows. Workspace Clippy passed for all targets with default and all features, with warnings denied. `cargo xtask policy` passed (191 files). AI-assisted with Codex. No game data or GPU used for local verification.
Emit eligible pages directly during the ordered region walk. A foreign region excludes every overlapping page, including partial edges.

AI-assisted-by: Codex Astra 6.2 High
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 01:06:16 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 21:27 UTC · original · approved these changes

LGTM — verified on Windows against origin/main (63bcca4).

  • Collecting tracked page runs without temporary trees cleanly reduces allocation overhead while still excluding pages split by private regions.
  • cargo test -p victory-gpu --lib watch:: -- --test-threads=1: 16 passed, 0 failed (including runtime_pages_excludes_a_page_split_by_a_private_region).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 21:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/3387#pullrequestreview-6080635426) · **approved these changes** LGTM — verified on Windows against `origin/main` (`63bcca4`). - Collecting tracked page runs without temporary trees cleanly reduces allocation overhead while still excluding pages split by private regions. - `cargo test -p victory-gpu --lib watch:: -- --test-threads=1`: 16 passed, 0 failed (including `runtime_pages_excludes_a_page_split_by_a_private_region`). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 21:51 UTC · original · approved these changes

Clean replacement that preserves exact equivalence with the previous BTreeSet::difference logic while avoiding temporary tree allocations.

Checked all boundary cases in runtime_pages (crates/victory-gpu/src/watch.rs:382-423): split 64 KiB pages containing one or more 4 KiB foreign regions, back-to-back foreign regions (run_start > at / PAGE safely yields an empty range), unaligned start/end, and early VirtualQuery == 0 termination on either the first or a later iteration (scanned_end tracks only queried regions).

Verification on origin/main (63bcca43):

  • cargo xtask policy: ok (191 files ok)
  • cargo clippy --locked -p victory-gpu --all-targets -- -D warnings (default and --features diagnostics): clean
  • cargo test --locked -p victory-gpu --features diagnostics -- watch::tests:: --test-threads=1: 16/16 passed on RTX 5090 and 16/16 passed on WARP (including runtime_pages_excludes_a_page_split_by_a_private_region)
  • Additional 2,000-case randomized differential oracle comparing the previous BTreeSet::difference implementation against the new run accumulator (including unaligned ranges, mixed 4 KiB sub-page regions, and simulated VirtualQuery == 0 early breaks): 2,000/2,000 matched identically.
**@⁠fuzeofficlal** on GitHub · 2026-11-26 21:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/3387#pullrequestreview-6080875604) · **approved these changes** Clean replacement that preserves exact equivalence with the previous `BTreeSet::difference` logic while avoiding temporary tree allocations. Checked all boundary cases in `runtime_pages` (`crates/victory-gpu/src/watch.rs:382-423`): split 64 KiB pages containing one or more 4 KiB foreign regions, back-to-back foreign regions (`run_start > at / PAGE` safely yields an empty range), unaligned `start`/`end`, and early `VirtualQuery == 0` termination on either the first or a later iteration (`scanned_end` tracks only queried regions). Verification on `origin/main` (`63bcca43`): - `cargo xtask policy`: ok (`191 files ok`) - `cargo clippy --locked -p victory-gpu --all-targets -- -D warnings` (default and `--features diagnostics`): clean - `cargo test --locked -p victory-gpu --features diagnostics -- watch::tests:: --test-threads=1`: 16/16 passed on RTX 5090 and 16/16 passed on WARP (including `runtime_pages_excludes_a_page_split_by_a_private_region`) - Additional 2,000-case randomized differential oracle comparing the previous `BTreeSet::difference` implementation against the new run accumulator (including unaligned ranges, mixed 4 KiB sub-page regions, and simulated `VirtualQuery == 0` early breaks): 2,000/2,000 matched identically.
Author
Owner

@⁠Jackster on GitHub · 2026-11-26 22:34 UTC · original

Windows 11, 63bcca4 + this PR, Radeon RX 7900 XTX:

  • watch::tests::runtime_pages_excludes_a_page_split_by_a_private_region by name: 1 passed.
  • cargo test -p victory-gpu --lib: 232 passed / 0 failed / 1 ignored (unpatched 63bcca4 here: 231).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.

Synthetic only. AI-assisted.

**@⁠Jackster** on GitHub · 2026-11-26 22:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/3387#issuecomment-7204796582) Windows 11, `63bcca4` + this PR, Radeon RX 7900 XTX: - `watch::tests::runtime_pages_excludes_a_page_split_by_a_private_region` by name: 1 passed. - `cargo test -p victory-gpu --lib`: 232 passed / 0 failed / 1 ignored (unpatched `63bcca4` here: 231). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. Synthetic only. AI-assisted.
This pull request can be merged automatically.
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/3387/head:github-bot/gh-3387'
git switch 'github-bot/gh-3387'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3387'
git switch 'github-bot/gh-3387'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3387'
git switch 'github-bot/gh-3387'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3387'
git switch 'main'
git merge --squash 'github-bot/gh-3387'
git switch 'main'
git merge --ff-only 'github-bot/gh-3387'
git switch 'main'
git merge 'github-bot/gh-3387'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!3387
No description provided.