Skip to content

Perf/memory guard batching - #1884

Open
VlREX wants to merge 5 commits into
Marvisak:mainfrom
VlREX:perf/memory-guard-batching
Open

VlREX wants to merge 5 commits into
Marvisak:mainfrom
VlREX:perf/memory-guard-batching

Conversation

@VlREX

@VlREX VlREX commented Nov 25, 2026

Copy link
Copy Markdown

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 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 added a commit to mercuryVM/VIctory that referenced this pull request Nov 25, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@mercuryVM mercuryVM left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested a175fff 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).

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 25, 2026

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

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

@CocoBeans64

Copy link
Copy Markdown

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants