Perf/memory guard batching #1882

Open
VlREX wants to merge 5 commits from upstream-pr/1884 into main
VlREX commented 2026-11-25 00:04:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by VlREX on 2026-11-25T00:04:03Z.


Optimize GPU memory guard batching by sorting and deduplicating alias pages and replacing repeated active-writer scans with a sorted sweep. Synthetic stress model: 4,063,488 linear comparisons reduced to 8,688 sweep checks, excluding sorting. Two independent reference implementations verified 421,875 cases with zero disagreements. Six Rust regression tests included. Native Windows/Rust validation and FPS benchmarking pending. AI-assisted (ChatGPT).

<!-- greyfinch-sync:Marvisak/VIctory:issue:6593992128 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1884). Originally posted by [VlREX](https://github.com/VlREX) on 2026-11-25T00:04:03Z. --- Optimize GPU memory guard batching by sorting and deduplicating alias pages and replacing repeated active-writer scans with a sorted sweep. Synthetic stress model: 4,063,488 linear comparisons reduced to 8,688 sweep checks, excluding sorting. Two independent reference implementations verified 421,875 cases with zero disagreements. Six Rust regression tests included. Native Windows/Rust validation and FPS benchmarking pending. AI-assisted (ChatGPT).
catminou4 commented 2026-11-25 01:07:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T00:32:43Z.

Review: COMMENTED


Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.

Memory guard batching (docs+gpu): perf rework of the guard path, pairs with #1885's loop-header work.

<!-- greyfinch-sync:Marvisak/VIctory:review:6049696962 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1884#pullrequestreview-6049696962). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T00:32:43Z. **Review:** COMMENTED --- Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff. Memory guard batching (docs+gpu): perf rework of the guard path, pairs with #1885's loop-header work.
mercuryVM commented 2026-11-25 03:02:35 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-25T02:58:23Z.

Review: APPROVED


Tested a175ffff on Windows 11, RTX 5070, MSVC:

  • cargo test -p victory-gpu passes on the head, including the new sweep tests and overlapping_kernel_writers_keep_pages_open_until_both_finish. The 2 other failures there (dynamic heap slots, memory table) also fail on main on this host.
  • Merged into our fork: workspace tests and clippy (both configs) as on main.

The sweep is right. With pages and spans sorted, a page is dropped exactly when some span that starts at or before it ends past it, which is what the max-end prefix gives. Skipping empty spans and keeping the linear check for small inputs is sensible.

One behavior change to note: the result is now sorted and deduplicated, where the old filter kept the caller's order. Its one caller only builds a set of pages from it, so this is fine today.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6051198907 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1884#pullrequestreview-6051198907). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-25T02:58:23Z. **Review:** APPROVED --- Tested a175ffff on Windows 11, RTX 5070, MSVC: - `cargo test -p victory-gpu` passes on the head, including the new sweep tests and `overlapping_kernel_writers_keep_pages_open_until_both_finish`. The 2 other failures there (dynamic heap slots, memory table) also fail on main on this host. - Merged into our fork: workspace tests and clippy (both configs) as on main. The sweep is right. With pages and spans sorted, a page is dropped exactly when some span that starts at or before it ends past it, which is what the max-end prefix gives. Skipping empty spans and keeping the linear check for small inputs is sensible. One behavior change to note: the result is now sorted and deduplicated, where the old filter kept the caller's order. Its one caller only builds a set of pages from it, so this is fine today. AI-assisted (Claude Code).
Marvisak commented 2026-11-25 09:06:10 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T08:17:08Z.


Automated triage for the maintainers.

Needs work. The verdict is unchanged.

Since the last review (a175fff → c14ab1d):

  • docs/memory-guard-batching.md is gone.
  • The over-long assertion in page_batch.rs is wrapped.
  • CI (check) now runs on this head and passes.

The code itself is unchanged: page_batch::eligible sorts and dedups the pages before protect in crates/victory-gpu/src/watch.rs and sweeps sorted writer ranges. It still reads as correct to me.

The benefit is still not shown. @CocoBeans64's native run (RX 6800 XT, 13f91ca) found no regressions and no crashes, but it measured the PR together with #2358. Over two runs per side, frame time and fps did not change beyond the ~6 % noise between identical baseline runs. So no gain is visible at frame level.

What would change the verdict: the guard counters this code affects, before and after, from one session of this PR alone. The diagnostics copystat line already prints them: "protecting … ms" in the watch-time section and "guards: … ms in the handler, … protect calls for … pages". If those show a real cut in protect time or calls, the module earns its place. If they don't, it adds 120 lines for nothing measurable. The PR title is also still the branch name ("Perf/memory guard batching"); please make it descriptive.

CI: passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7156837250 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1884#issuecomment-7156837250). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T08:17:08Z. --- <!-- victory-triage v1 head=c14ab1d8144ac2a681eb7a56e34d432af5c8412d verdict=needs-work at=2026-11-25T20:22:45Z --> Automated triage for the maintainers. **Needs work.** The verdict is unchanged. **Since the last review (`a175fff` → `c14ab1d`):** - `docs/memory-guard-batching.md` is gone. - The over-long assertion in `page_batch.rs` is wrapped. - CI (`check`) now runs on this head and passes. The code itself is unchanged: `page_batch::eligible` sorts and dedups the pages before `protect` in `crates/victory-gpu/src/watch.rs` and sweeps sorted writer ranges. It still reads as correct to me. The benefit is still not shown. @CocoBeans64's native run (RX 6800 XT, `13f91ca`) found no regressions and no crashes, but it measured the PR together with #2358. Over two runs per side, frame time and fps did not change beyond the ~6 % noise between identical baseline runs. So no gain is visible at frame level. What would change the verdict: the guard counters this code affects, before and after, from one session of this PR alone. The `diagnostics` copystat line already prints them: "protecting … ms" in the watch-time section and "guards: … ms in the handler, … protect calls for … pages". If those show a real cut in protect time or calls, the module earns its place. If they don't, it adds 120 lines for nothing measurable. The PR title is also still the branch name ("Perf/memory guard batching"); please make it descriptive. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
CocoBeans64 commented 2026-11-25 20:06:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by CocoBeans64 on 2026-11-25T19:29:55Z.


Native Windows run as asked, on Windows 10 22H2 (19045), RX 6800 XT (driver 32.0.21045.5002), Ryzen 7 7800X3D. The PR is merged with #2358 on 13f91ca, plus an Agility SDK runtime (#84), diag build.
cargo test -p victory-gpu: 201 passed, 1 failed. The failure, a_texture_written_in_one_format_reads_in_another_through_a_placed_view, fails the same way on 13f91ca without the PR (#1999).
Benchmark: the same saved game in the prologue, menus by hand, then a scripted camera loop. The figures cover the 300 s after the world shows. Two runs per side:

fps (median) ms/frame (mean) preparing copies GPU copying back
13f91ca 1.5 / 1.5 877 / 773 318 / 297 183 / 147 234 / 198 175 / 177
+ #1884 + #2358 1.6 / 1.5 757 / 764 305 / 289 166 / 152 191 / 196 166 / 156

Two identical baseline runs differ by about 6 % in mean frame time.
No regression and no crash; no fps change beyond that noise.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7172379863 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1884#issuecomment-7172379863). Originally posted by [CocoBeans64](https://github.com/CocoBeans64) on 2026-11-25T19:29:55Z. --- Native Windows run as asked, on Windows 10 22H2 (19045), RX 6800 XT (driver 32.0.21045.5002), Ryzen 7 7800X3D. The PR is merged with #2358 on `13f91ca`, plus an Agility SDK runtime (#84), diag build. `cargo test -p victory-gpu`: 201 passed, 1 failed. The failure, `a_texture_written_in_one_format_reads_in_another_through_a_placed_view`, fails the same way on `13f91ca` without the PR (#1999). Benchmark: the same saved game in the prologue, menus by hand, then a scripted camera loop. The figures cover the 300 s after the world shows. Two runs per side: | | fps (median) | ms/frame (mean) | preparing | copies | GPU | copying back | |---|---|---|---|---|---|---| | `13f91ca` | 1.5 / 1.5 | 877 / 773 | 318 / 297 | 183 / 147 | 234 / 198 | 175 / 177 | | + #1884 + #2358 | 1.6 / 1.5 | 757 / 764 | 305 / 289 | 166 / 152 | 191 / 196 | 166 / 156 | Two identical baseline runs differ by about 6 % in mean frame time. No regression and no crash; no fps change beyond that noise.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1884:upstream-pr/1884'
git switch 'upstream-pr/1884'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/1884'
git switch 'upstream-pr/1884'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1884'
git switch 'upstream-pr/1884'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1884'
git switch 'main'
git merge --squash 'upstream-pr/1884'
git switch 'main'
git merge --ff-only 'upstream-pr/1884'
git switch 'main'
git merge 'upstream-pr/1884'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!1882
No description provided.