GPU: open guarded pages in runs, not one VirtualProtect at a time #2849

Open
github-bot wants to merge 2 commits from github-bot/gh-2849 into main AGit
Owner

@⁠Therecalloftheonion on GitHub · 2026-11-25 22:14 UTC · original
Therecalloftheonion:perf/guard-open-runs → main · +182 −13 · 1 files · 2 commits · open

Problem

Issue #400 puts about 600 ms a frame in the guard lock on an RTX 2080, with ~3,800 VirtualProtect calls a frame. Two hot paths opened guarded pages one call at a time:

  • changed_here (a title write over a range, e.g. a memset or a file read) collected the protected pages of the range and called VirtualProtect per page.
  • Tracked::drop did the same for every page freed when the last tracker let go of it.

The pages are already in sorted order in both callers.

Change

open_pages groups consecutive guarded pages and open_range makes one VirtualProtect call per run. Only runs where every page is guarded are opened; unguarded pages are skipped exactly as before, and the guard set, changed marks and saved snapshots are unchanged.

This is not #1884: that sorts/deduplicates alias pages and replaces active-writer scans; this batches the write-access restore calls themselves. It does not touch the copy path or the listed copy PRs.

Benchmark

cargo test --release -p victory-gpu benchmark_guard_open_runs -- --ignored --test-threads=1 --nocapture, 512 pages, 20 rounds, RX 6700 XT, release:

path VirtualProtect calls time
one call per page (old) 10,240 4.27 ms
one call per run (new) 20 1.79 ms

The test-only switch runs both paths on the same protected pages, so this is a direct before/after. It measures the write-access restore step only, not game FPS; no title data was available here.

Tests

  • New watch::tests::a_bulk_write_opens_guarded_pages_in_one_call: an 8-page write opens the run with one call and every page is read-write again.
  • cargo test -p victory-gpu --lib: 227 passed, 2 ignored. Two unrelated upstream tests are filtered because they fail on main on this machine (the 2^21 view-heap assertion and the copy-pair placement test).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • rustfmt --check on the file reports pre-existing differences (first at line 100, unrelated); the new code follows the surrounding style.

Regressions

  • open_pages relies on the sorted page lists both callers already provide; a future unsorted caller would lose batching but not correctness (unguarded pages are skipped).
  • Opening a run is only done when every page in it is guarded; a gap breaks the run.
  • Runtime behaviour and GPU synchronization are unchanged: this only restores page protection before the write that already caused it.

All Windows D3D12 vendors benefit equally; it is host CPU/kernel work, not GPU-specific.

**@⁠Therecalloftheonion** on GitHub · 2026-11-25 22:14 UTC · [original](https://github.com/Marvisak/VIctory/pull/2849) `Therecalloftheonion:perf/guard-open-runs` → `main` · +182 −13 · 1 files · 2 commits · open ## Problem Issue #400 puts about 600 ms a frame in the guard lock on an RTX 2080, with ~3,800 `VirtualProtect` calls a frame. Two hot paths opened guarded pages one call at a time: - `changed_here` (a title write over a range, e.g. a `memset` or a file read) collected the protected pages of the range and called `VirtualProtect` per page. - `Tracked::drop` did the same for every page freed when the last tracker let go of it. The pages are already in sorted order in both callers. ## Change `open_pages` groups consecutive guarded pages and `open_range` makes **one `VirtualProtect` call per run**. Only runs where every page is guarded are opened; unguarded pages are skipped exactly as before, and the guard set, changed marks and saved snapshots are unchanged. This is not #1884: that sorts/deduplicates alias pages and replaces active-writer scans; this batches the write-access restore calls themselves. It does not touch the copy path or the listed copy PRs. ## Benchmark `cargo test --release -p victory-gpu benchmark_guard_open_runs -- --ignored --test-threads=1 --nocapture`, 512 pages, 20 rounds, RX 6700 XT, release: | path | VirtualProtect calls | time | |---|---:|---:| | one call per page (old) | 10,240 | 4.27 ms | | one call per run (new) | **20** | **1.79 ms** | The test-only switch runs both paths on the same protected pages, so this is a direct before/after. It measures the write-access restore step only, not game FPS; no title data was available here. ## Tests - New `watch::tests::a_bulk_write_opens_guarded_pages_in_one_call`: an 8-page write opens the run with one call and every page is read-write again. - `cargo test -p victory-gpu --lib`: **227 passed**, 2 ignored. Two unrelated upstream tests are filtered because they fail on `main` on this machine (the 2^21 view-heap assertion and the copy-pair placement test). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `rustfmt --check` on the file reports pre-existing differences (first at line 100, unrelated); the new code follows the surrounding style. ## Regressions - `open_pages` relies on the sorted page lists both callers already provide; a future unsorted caller would lose batching but not correctness (unguarded pages are skipped). - Opening a run is only done when every page in it is guarded; a gap breaks the run. - Runtime behaviour and GPU synchronization are unchanged: this only restores page protection before the write that already caused it. All Windows D3D12 vendors benefit equally; it is host CPU/kernel work, not GPU-specific.
A bulk title write and a dropped tracker both make guarded pages writable again: changed_here opened each protected page of a range with its own VirtualProtect, and Tracked::drop opened each freed page the same way. The pages are sorted in both callers, so open_pages now groups consecutive guarded pages and open_range makes one VirtualProtect call for the run.

The guard state, the pages opened and the changed marks are the same; only runs that are wholly guarded are opened, and pages not guarded are skipped as before.

Benchmark (512 pages, 20 rounds, release, RX 6700 XT): one call per page 10,240 VirtualProtect calls in 4.27 ms; one call per run 20 calls in 1.79 ms, a 2.4x reduction in the open step. This is not a game-FPS measurement.

Tests: a_bulk_write_opens_guarded_pages_in_one_call (8-page run, one call, every page read-write again); the watch suite passes (16 tests); the GPU suite passes apart from two unrelated upstream failures on this machine. A test-only switch runs the old per-page path in benchmark_guard_open_runs for the before/after numbers.
VirtualProtect returns 0 with ERROR_INVALID_ADDRESS (487) when a run crosses two separate VirtualAlloc regions or an uncommitted page, even when every page is guarded and ours. open_range removed the pages from the guard set first and ignored the BOOL, so on failure they stayed read-only but unguarded; the next write faulted and could access-violate.

Check the batch result and, when it fails, restore the run one page at a time as the old path did. The pages were already taken out of the guard set; the fallback opens each of them, and a page that is gone fails harmlessly as before.

Adds a regression test with two adjacent pages allocated separately: both are guarded, the batch is attempted, and both must end up PAGE_READWRITE with the guard set empty. The benchmark is unchanged when the batch succeeds (4.13 ms against 1.61 ms over 20 rounds of 512 pages).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:15:50 +00:00
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 22:34 UTC · original

Tested 7be4f20d on Windows 11 (RTX 5090 + WARP) and benchmarked --release, but caught a real Windows VirtualProtect boundary bug in open_range:

Bug: VirtualProtect fails across adjacent VirtualAlloc regions without fallback

  • open_range removes [first, last) from g.protected and issues one VirtualProtect((first * PAGE) as ..., (last - first) * PAGE, PAGE_READWRITE, &mut old) while ignoring the BOOL return value.
  • On Windows, VirtualProtect fails with ERROR_INVALID_ADDRESS (487) and leaves all pages untouched whenever the range crosses two separate VirtualAlloc reservations/allocations (even if they are contiguous and all present in g.protected) or contains a freed/uncommitted page.
  • Confirmed locally on Windows 11 with two adjacent 64 KiB VirtualAlloc(..., PAGE_READONLY) regions: a single 128 KiB VirtualProtect(..., PAGE_READWRITE) returned ok=0, err=487, while per-page calls succeeded (ok=1).
  • Because g.protected already removed those pages, the next write hits a still-PAGE_READONLY page outside the guard set and crashes with an unhandled 0xc0000005.
  • Checking VirtualProtect(...) != 0 and falling back to per-page VirtualProtect when last - first > 1 (matching protect_noting in watch.rs) avoids this cleanly.

Local test & benchmark results

  • cargo xtask policy (190 ok), clippy default & diagnostics 0 warnings; watch::tests 16/16 & shadow::tests 9/9 passed on RTX 5090 and WARP.
  • --release benchmark_guard_open_runs: 4.5307 ms (10,240 calls) -> 1.2228 ms (20 calls, ~3.71x faster).
  • Note: overlaps/conflicts directly with #2848 (2851648) in crates/victory-gpu/src/watch.rs.
**@⁠fuzeofficlal** on GitHub · 2026-11-25 22:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/2849#issuecomment-7176529910) Tested `7be4f20d` on Windows 11 (RTX 5090 + WARP) and benchmarked `--release`, but caught a real Windows `VirtualProtect` boundary bug in `open_range`: ### Bug: `VirtualProtect` fails across adjacent `VirtualAlloc` regions without fallback - `open_range` removes `[first, last)` from `g.protected` and issues one `VirtualProtect((first * PAGE) as ..., (last - first) * PAGE, PAGE_READWRITE, &mut old)` while ignoring the `BOOL` return value. - On Windows, `VirtualProtect` fails with `ERROR_INVALID_ADDRESS` (`487`) and leaves **all** pages untouched whenever the range crosses two separate `VirtualAlloc` reservations/allocations (even if they are contiguous and all present in `g.protected`) or contains a freed/uncommitted page. - Confirmed locally on Windows 11 with two adjacent 64 KiB `VirtualAlloc(..., PAGE_READONLY)` regions: a single 128 KiB `VirtualProtect(..., PAGE_READWRITE)` returned `ok=0, err=487`, while per-page calls succeeded (`ok=1`). - Because `g.protected` already removed those pages, the next write hits a still-`PAGE_READONLY` page outside the guard set and crashes with an unhandled `0xc0000005`. - Checking `VirtualProtect(...) != 0` and falling back to per-page `VirtualProtect` when `last - first > 1` (matching `protect_noting` in `watch.rs`) avoids this cleanly. ### Local test & benchmark results - `cargo xtask policy` (190 ok), clippy default & `diagnostics` 0 warnings; `watch::tests` 16/16 & `shadow::tests` 9/9 passed on RTX 5090 and WARP. - `--release` `benchmark_guard_open_runs`: `4.5307 ms` (10,240 calls) -> `1.2228 ms` (20 calls, **~3.71x faster**). - Note: overlaps/conflicts directly with #2848 (`2851648`) in `crates/victory-gpu/src/watch.rs`.
Author
Owner

@⁠Therecalloftheonion on GitHub · 2026-11-25 22:52 UTC · original

Thanks @⁠fuzeofficlal. Confirmed and accepted: VirtualProtect can fail across two separate VirtualAlloc regions, and my open_range removed the pages from protected before ignoring the return. A later write then faults on a still-read-only page outside the guard set.

I also see #2848 item 6 implements the same open-runs optimization. This PR is a duplicate of that item, so I am closing it rather than carrying a second copy. The failure and the fallback belong on #2848; I have left the detail there. No credit claimed here.

**@⁠Therecalloftheonion** on GitHub · 2026-11-25 22:52 UTC · [original](https://github.com/Marvisak/VIctory/pull/2849#issuecomment-7176891007) Thanks @⁠fuzeofficlal. Confirmed and accepted: `VirtualProtect` can fail across two separate `VirtualAlloc` regions, and my `open_range` removed the pages from `protected` before ignoring the return. A later write then faults on a still-read-only page outside the guard set. I also see #2848 item 6 implements the same open-runs optimization. This PR is a duplicate of that item, so I am closing it rather than carrying a second copy. The failure and the fallback belong on #2848; I have left the detail there. No credit claimed here.
Author
Owner

@⁠Therecalloftheonion on GitHub · 2026-11-25 23:02 UTC · original

Reopened with the fix for the ERROR_INVALID_ADDRESS (487) failure found by @⁠fuzeofficlal.

open_range now checks the batch VirtualProtect result and, when it is 0, restores the run one page at a time (the pages were already taken out of g.protected; the per-page calls put them back to PAGE_READWRITE and a page that is gone still fails harmlessly, as the old path did).

Added open_runs_falls_back_across_separate_allocations: two adjacent pages allocated separately, both guarded, then open_pages; both must be PAGE_READWRITE and no longer in protected. On this machine the two-page batch is the only run, so the test exercises the fallback path.

Benchmark unchanged when the batch succeeds: 512 pages, 20 rounds, release: 4.13 ms (10,240 calls) vs 1.61 ms (20 calls). The fix adds no work to the success path.

Still overlaps #2848 item 6 (2851648), which has the same batching and the same missing fallback; the fix applies there too. Maintainers can keep either; I am not claiming a separate contribution for the same optimization.

**@⁠Therecalloftheonion** on GitHub · 2026-11-25 23:02 UTC · [original](https://github.com/Marvisak/VIctory/pull/2849#issuecomment-7177068876) Reopened with the fix for the `ERROR_INVALID_ADDRESS` (487) failure found by @⁠fuzeofficlal. `open_range` now checks the batch `VirtualProtect` result and, when it is 0, restores the run one page at a time (the pages were already taken out of `g.protected`; the per-page calls put them back to `PAGE_READWRITE` and a page that is gone still fails harmlessly, as the old path did). Added `open_runs_falls_back_across_separate_allocations`: two adjacent pages allocated separately, both guarded, then `open_pages`; both must be `PAGE_READWRITE` and no longer in `protected`. On this machine the two-page batch is the only run, so the test exercises the fallback path. Benchmark unchanged when the batch succeeds: 512 pages, 20 rounds, release: 4.13 ms (10,240 calls) vs 1.61 ms (20 calls). The fix adds no work to the success path. Still overlaps #2848 item 6 (`2851648`), which has the same batching and the same missing fallback; the fix applies there too. Maintainers can keep either; I am not claiming a separate contribution for the same optimization.
Author
Owner

@⁠Machad3x on GitHub · 2026-11-25 23:18 UTC · original · edited 2026-11-25 23:26 UTC

Hardware result at head 7be4f20d, cherry-picked onto a fork stack that opens a changed page's aliases too, RTX 3080 Ti, driver 621.24.

  1. A run can cross allocations: with two mapped views of one memory next to each other in the sorted pages, the single VirtualProtect fails (a call cannot span allocations), the pages are already removed from the guard set, and the next write faults for ever (access violation in a two-mapping tracker test the stack carries). Opening page by page when the call returns 0 fixed the test. On main this needs two adjacent views both in one run.
  2. Timing: correction of what this comment first said. We compared one run with the change (724 ms a frame, guard lock 305 ms) against one without (675 ms, 114 ms), but a later run without it measured 325 ms of guard lock, so that figure swings between runs by more than the difference. We have no measured effect either way.

Ran with AI assistance (Claude Code).

**@⁠Machad3x** on GitHub · 2026-11-25 23:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/2849#issuecomment-7177396382) · edited 2026-11-25 23:26 UTC Hardware result at head 7be4f20d, cherry-picked onto a fork stack that opens a changed page's aliases too, RTX 3080 Ti, driver 621.24. 1. A run can cross allocations: with two mapped views of one memory next to each other in the sorted pages, the single `VirtualProtect` fails (a call cannot span allocations), the pages are already removed from the guard set, and the next write faults for ever (access violation in a two-mapping tracker test the stack carries). Opening page by page when the call returns 0 fixed the test. On `main` this needs two adjacent views both in one run. 2. Timing: **correction** of what this comment first said. We compared one run with the change (724 ms a frame, guard lock 305 ms) against one without (675 ms, 114 ms), but a later run without it measured 325 ms of guard lock, so that figure swings between runs by more than the difference. We have no measured effect either way. Ran with AI assistance (Claude Code).
Author
Owner

@⁠liandraraiane on GitHub · 2026-11-26 02:42 UTC · original

Measured on a Ryzen 7 5700G (16 threads) + RTX 3060, Windows 11, release, against their base f3578e3, with a guard-lock contention benchmark (writer threads faulting on guarded pages while a submission thread arms and takes every tracker in rounds, plus a kernel-writer thread opening 8-page ranges with writing every 200 µs; guard_lock_contention_bench on branch liandraraiane/VIctory:perf/guard-lock-contention). Median of 5 rotated runs:

writers fault p99 µs (base / #2848 / #2849) 8-page writing p50 µs p99 µs
8 424 / 406 / 417 387 / 390 / 390 822 / 702 / 754
15 588 / 589 / 607 418 / 414 / 426 1131 / 1125 / 1150

With writers pausing 50 µs between writes the picture is the same. Under contention the time is waiting for the guard lock, not the open calls, so batching them does not show here. Even with one writer, an 8-page writing takes ~270 µs, almost all queued behind takes. Both pass a 12-thread stress test (writes vs takes and copies, no write lost, no stray fault) 20/20. Not tested: the title; ranges longer than 8 pages; #2848's other six changes.

AI use: Claude Code ran the builds and benchmarks on this machine and drafted this comment.

**@⁠liandraraiane** on GitHub · 2026-11-26 02:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/2849#issuecomment-7181042769) Measured on a Ryzen 7 5700G (16 threads) + RTX 3060, Windows 11, release, against their base `f3578e3`, with a guard-lock contention benchmark (writer threads faulting on guarded pages while a submission thread arms and takes every tracker in rounds, plus a kernel-writer thread opening 8-page ranges with `writing` every 200 µs; `guard_lock_contention_bench` on branch `liandraraiane/VIctory:perf/guard-lock-contention`). Median of 5 rotated runs: | writers | fault p99 µs (base / #2848 / #2849) | 8-page `writing` p50 µs | p99 µs | |---|---|---|---| | 8 | 424 / 406 / 417 | 387 / 390 / 390 | 822 / 702 / 754 | | 15 | 588 / 589 / 607 | 418 / 414 / 426 | 1131 / 1125 / 1150 | With writers pausing 50 µs between writes the picture is the same. Under contention the time is waiting for the guard lock, not the open calls, so batching them does not show here. Even with one writer, an 8-page `writing` takes ~270 µs, almost all queued behind takes. Both pass a 12-thread stress test (writes vs takes and copies, no write lost, no stray fault) 20/20. Not tested: the title; ranges longer than 8 pages; #2848's other six changes. AI use: Claude Code ran the builds and benchmarks on this machine and drafted this comment.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 03:23 UTC · original

Automated triage for the maintainers.

Verdict: needs work (small). The batching in open_pages / open_range (crates/victory-gpu/src/watch.rs) looks correct. Runs are opened only when every page is guarded. The per-page fallback when the batched VirtualProtect returns 0 covers the cross-allocation failure fuzeofficlal found. The pages leave protected as before, and OpenPages still counts pages. What needs fixing before a merge:

  • The diff deletes the doc comment of the existing test writes_mark_every_tracker_of_their_page ("Everything is changed at first; …"). Please restore it.
  • The doc comment on open_pages links to [open], which this PR removes.

For the maintainers: #2848 (item 6) makes the same batching change in watch.rs without the fallback, and the two conflict. If that item is kept, it needs the same fallback. The microbenchmark shows the restore step about 2.4x faster. liandraraiane's contention benchmark and Machad3x's title run show no measured effect, so the gain in the title is unproven.

CI: passing (check).


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 03:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/2849#issuecomment-7181678704) <!-- victory-triage v1 head=7b1316af3863e83ddba383fe684755eeba76e69a verdict=needs-work at=2026-11-26T03:23:34Z --> Automated triage for the maintainers. **Verdict: needs work (small).** The batching in `open_pages` / `open_range` (`crates/victory-gpu/src/watch.rs`) looks correct. Runs are opened only when every page is guarded. The per-page fallback when the batched `VirtualProtect` returns 0 covers the cross-allocation failure fuzeofficlal found. The pages leave `protected` as before, and `OpenPages` still counts pages. What needs fixing before a merge: - The diff deletes the doc comment of the existing test `writes_mark_every_tracker_of_their_page` ("Everything is changed at first; …"). Please restore it. - The doc comment on `open_pages` links to `[`open`]`, which this PR removes. For the maintainers: #2848 (item 6) makes the same batching change in `watch.rs` without the fallback, and the two conflict. If that item is kept, it needs the same fallback. The microbenchmark shows the restore step about 2.4x faster. liandraraiane's contention benchmark and Machad3x's title run show no measured effect, so the gain in the title is unproven. CI: passing (`check`). --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠MeMako on GitHub · 2026-11-26 06:28 UTC · original

Verified #2849 (7b1316a) on Windows 11 (10.0.26200, Ryzen 9 7950X, RX 9070 XT, driver 32.0.32029.2010, 32 GB RAM).

Tests & Microbenchmark

  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings: clean.
  • victory-gpu: 272/272 passed (including a_bulk_write_opens_guarded_pages_in_one_call).
  • benchmark_guard_open_runs (--release, 512 pages × 20 rounds):
    • One call per page (10,240 VirtualProtect calls): 5.120 ms
    • One call per run (20 VirtualProtect calls): 1.336 ms (3.83x faster)

Live Title Verification & Integration Note

  • Setup: Local integration branch (main 63bcca4 + #2051 + #2472 + #2918 + #1010 + #2130 with VRAM upload flags off + #3055 + #2914), adding #2985 + #2849 + #3035 together in the same live run (n=54 world frames / n=38 heavy frames vs. n=51 / n=38 baseline).
  • Result: 0 crashes or faults through the intro and opening world scene.
  • Subsystem metrics (steady tail, last 20 heavy frames — 6,186 draws vs. 5,290 draws in baseline):
    • prep → deferred: 92.7 → 71.8 ms (-20.9 ms / -22.5%)
    • copy_back: 99.2 → 75.5 ms (-23.7 ms / -23.9%)
    • (Both watch.rs timers reflect #2849 and #3035 combined; #2985 affects texture detile/upload separately.)
  • Combined frame-time delta (all three PRs #2985 + #2849 + #3035 together): steady-tail frame time dropped 453.3 → 423.6 ms (2.20 → 2.40 fps), even with +17% more draws.
  • Note for combining with #3035: Since #2849 replaces single-page open() with open_range(), #3035's opened(page).fetch_add(1, Ordering::Relaxed) bump simply moves inside open_range()'s if g.protected.remove(&page) loop (the single removal site) so both PRs compose cleanly.

Hardware runs were performed by me on my 7950X / RX 9070 XT; comment drafted with Antigravity.

**@⁠MeMako** on GitHub · 2026-11-26 06:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/2849#issuecomment-7184470610) Verified `#2849` (`7b1316a`) on Windows 11 (`10.0.26200`, Ryzen 9 7950X, RX 9070 XT, driver `32.0.32029.2010`, 32 GB RAM). ### Tests & Microbenchmark - `cargo clippy -p victory-gpu --all-targets --locked -- -D warnings`: clean. - `victory-gpu`: **272/272 passed** (including `a_bulk_write_opens_guarded_pages_in_one_call`). - `benchmark_guard_open_runs` (`--release`, 512 pages × 20 rounds): - One call per page (10,240 `VirtualProtect` calls): **5.120 ms** - One call per run (20 `VirtualProtect` calls): **1.336 ms** (**3.83x faster**) ### Live Title Verification & Integration Note - **Setup:** Local integration branch (`main` `63bcca4` + `#2051` + `#2472` + `#2918` + `#1010` + `#2130` with VRAM upload flags off + `#3055` + `#2914`), adding `#2985` + `#2849` + `#3035` together in the same live run (`n=54` world frames / `n=38` heavy frames vs. `n=51` / `n=38` baseline). - **Result:** 0 crashes or faults through the intro and opening world scene. - **Subsystem metrics (steady tail, last 20 heavy frames — `6,186` draws vs. `5,290` draws in baseline):** - `prep → deferred`: **92.7 → 71.8 ms** (**-20.9 ms / -22.5%**) - `copy_back`: **99.2 → 75.5 ms** (**-23.7 ms / -23.9%**) - *(Both `watch.rs` timers reflect `#2849` and `#3035` combined; `#2985` affects texture detile/upload separately.)* - **Combined frame-time delta (all three PRs `#2985` + `#2849` + `#3035` together):** steady-tail frame time dropped **453.3 → 423.6 ms** (**2.20 → 2.40 fps**), even with +17% more draws. - **Note for combining with `#3035`:** Since `#2849` replaces single-page `open()` with `open_range()`, `#3035`'s `opened(page).fetch_add(1, Ordering::Relaxed)` bump simply moves inside `open_range()`'s `if g.protected.remove(&page)` loop (the single removal site) so both PRs compose cleanly. *Hardware runs were performed by me on my 7950X / RX 9070 XT; comment drafted with Antigravity.*
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 22:51 UTC · original · reviewed

Correct batching: the debug_assert that a run is fully guarded is exactly the safety property needed — one VirtualProtect over a partial run would silently change protection of pages that aren't ours or that another tracker watches. Collecting to_open first keeps the same semantics as the per-page loop. LGTM.

**@⁠kotekompotek** on GitHub · 2026-11-25 22:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/2849#pullrequestreview-6066073087) · **reviewed** Correct batching: the debug_assert that a run is fully guarded is exactly the safety property needed — one VirtualProtect over a partial run would silently change protection of pages that aren't ours or that another tracker watches. Collecting to_open first keeps the same semantics as the per-page loop. LGTM.
Author
Owner

@⁠crashbashash on GitHub · 2026-11-26 10:10 UTC · original

On "the gain in the title is unproven": here is an in-game A/B from Linux, where every VirtualProtect is a Wine call
plus an mprotect, so the per-call cost the batching saves is larger than on Windows. RX 6800 XT, RADV,
GE-Proton11-14 (with a newer vkd3d-proton and the wineserver view tree), diag build of main 219878a plus our
Linux commits, with and without this PR (7b1316a, merges cleanly), a save in the prison, 120 s in the world, idle
machine, runs interleaved.

without with this PR
runs 2 2
world frame, median 619, 667 ms 490, 530 ms
of it preparing submissions 300, 303 ms 219, 249 ms
submissions per frame 23.3, 23.2 22.8, 23.0

No crash or change in behaviour in those runs, and the crate's tests pass under Wine, the fallback test included
(Wine also refuses a VirtualProtect whose range is not inside one view). Two runs a side is not a precise figure,
but both are well apart.

AI-assisted (Claude Code). No game data attached.

**@⁠crashbashash** on GitHub · 2026-11-26 10:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/2849#issuecomment-7188997004) On "the gain in the title is unproven": here is an in-game A/B from Linux, where every `VirtualProtect` is a Wine call plus an `mprotect`, so the per-call cost the batching saves is larger than on Windows. RX 6800 XT, RADV, GE-Proton11-14 (with a newer vkd3d-proton and the wineserver view tree), `diag` build of `main` `219878a` plus our Linux commits, with and without this PR (`7b1316a`, merges cleanly), a save in the prison, 120 s in the world, idle machine, runs interleaved. | | without | with this PR | |---|---|---| | runs | 2 | 2 | | world frame, median | 619, 667 ms | 490, 530 ms | | of it preparing submissions | 300, 303 ms | 219, 249 ms | | submissions per frame | 23.3, 23.2 | 22.8, 23.0 | No crash or change in behaviour in those runs, and the crate's tests pass under Wine, the fallback test included (Wine also refuses a `VirtualProtect` whose range is not inside one view). Two runs a side is not a precise figure, but both are well apart. AI-assisted (Claude Code). No game data attached.
Author
Owner

@⁠RobertAndreiGit on GitHub · 2026-11-26 13:59 UTC · original

RTX 3060 Ti / Proton: batching avoided 380 VirtualProtect calls, but we saw no world-frame improvement in a downstream A/B. We adapted 7be4f20 and the per-block fallback in 7b1316a to cool_fox; this is not a test of the upstream branch unchanged. This fork first uses VirtualQuery to check that a run fits in one committed, uniformly read-only region. The 380 counts avoided protection calls, not net syscalls; 577 candidate runs took the per-block path.

Median of 15 qualifying world intervals Control Batched opens
Frame time (middle 50%) 282.4 ms (176–652) 365.3 ms (182–670)
FPS 3.5 2.7
Draws / dropped for lack of a pipeline 3,903 / 308 3,647 / 308

Same release executable (SHA-256 starts d798074e88b7), same save and initial pipeline cache; only VICTORY_BATCH_OPEN=1 changed. Series S, host temporal 720p → 1080p, 24 ms pipeline wait; Ryzen 5 5600, 32 GB RAM, RTX 3060 Ti 8 GB, NVIDIA 615.78.08, CachyOS Proton / vkd3d-proton 3.2.0. The focused Proton test for uniform and mixed protections passed.

The player preferred the control and found the batching run visibly slower. One non-replayed run per setting, with overlapping frame times; this does not contradict the PR’s isolated open-step benchmark. A useful discriminator would be timing VirtualQuery, successful batches and fallbacks separately during world frames.

**@⁠RobertAndreiGit** on GitHub · 2026-11-26 13:59 UTC · [original](https://github.com/Marvisak/VIctory/pull/2849#issuecomment-7194113918) <!-- cool-fox-world-3060ti-20261126:victory-2849.md --> **RTX 3060 Ti / Proton: batching avoided 380 `VirtualProtect` calls, but we saw no world-frame improvement in a downstream A/B.** We adapted `7be4f20` and the per-block fallback in `7b1316a` to `cool_fox`; this is not a test of the upstream branch unchanged. This fork first uses `VirtualQuery` to check that a run fits in one committed, uniformly read-only region. The 380 counts avoided protection calls, **not net syscalls**; 577 candidate runs took the per-block path. | Median of 15 qualifying world intervals | Control | Batched opens | |---|---:|---:| | Frame time (middle 50%) | 282.4 ms (176–652) | 365.3 ms (182–670) | | FPS | 3.5 | 2.7 | | Draws / dropped for lack of a pipeline | 3,903 / 308 | 3,647 / 308 | Same release executable (SHA-256 starts `d798074e88b7`), same save and initial pipeline cache; only `VICTORY_BATCH_OPEN=1` changed. Series S, host temporal 720p → 1080p, 24 ms pipeline wait; Ryzen 5 5600, 32 GB RAM, RTX 3060 Ti 8 GB, NVIDIA 615.78.08, CachyOS Proton / vkd3d-proton 3.2.0. The focused Proton test for uniform and mixed protections passed. The player preferred the control and found the batching run visibly slower. One non-replayed run per setting, with overlapping frame times; this does not contradict the PR’s isolated open-step benchmark. A useful discriminator would be timing `VirtualQuery`, successful batches and fallbacks separately during world frames.
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/2849/head:github-bot/gh-2849'
git switch 'github-bot/gh-2849'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2849'
git switch 'github-bot/gh-2849'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2849'
git switch 'github-bot/gh-2849'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2849'
git switch 'main'
git merge --squash 'github-bot/gh-2849'
git switch 'main'
git merge --ff-only 'github-bot/gh-2849'
git switch 'main'
git merge 'github-bot/gh-2849'
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!2849
No description provided.