View memory guarded beside the submission's asking #109

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

@⁠mgrein on GitHub · 2026-11-30 13:06 UTC · original
mgrein:guard-first → main · +0 −0 · 0 files · 48 commits · closed without merging

Follow-up to #80 (batched guards). With VICTORY_ASK_FIRST=1, the submission's write-watch asking starts on its own thread (victory-ask), next to the submitting thread's planning. guard_ahead then ran on the submitting thread after that asking had been waited for. In the world of a new retail game that guarding cost 11 % of the submitting thread (~4.8 ms a frame), almost all of it VirtualProtect calls in cover() on other views of written blocks.

This moves the guarding next to the asking. The asking job hands the guarding to a wide helper (shadow::wide_run) and does its own asking meanwhile. The asking only touches write-watched memory and guard_ahead keeps only view memory, so neither holds the other's pages (Askings). The submitting thread still calls guard_ahead at the old spot and finds the ranges published. A block written in between isn't published and gets guarded by its own refresh, which is how guard_ahead already behaves.

  • VICTORY_GUARD_FIRST=0 guards after the wait, as before.
  • VICTORY_GUARD_FIRST=ab switches every 20 seconds and logs each switch (guard-first switch <unix ms> on|off), for an A/B inside one run.

Measured

RTX 4070, Ryzen 5 5600X, Series S profile, DLSS quality + frame generation, VICTORY_SUBMIT_SPLIT=1, VICTORY_ASK_FIRST=1, VICTORY_OFF_LINE=1. Each test is a 10-minute idle run in the world with =ab, pairing neighbouring 20 s windows.

per frame before after
asking + its wait + guarding, submitting thread 8.9 ms 8.1 ms
submitting thread — ~0.9 ms less (23 of 26 pairs)
frame median — ~0.5 ms less (18 of 26 pairs)

The gain is smaller than the guarding's cost. The kernel probably serializes part of GetWriteWatch and VirtualProtect under the process's address-space lock. A first version guarded after the asking on the asking thread and gained nothing (12 of 26 pairs), because the planning beside it is shorter than the asking.

cargo test -p victory-gpu --lib passes.

🤖 Generated with Claude Code

**@⁠mgrein** on GitHub · 2026-11-30 13:06 UTC · [original](https://github.com/readmet3xt-lab/foxhound/pull/109) `mgrein:guard-first` → `main` · +0 −0 · 0 files · 48 commits · closed without merging Follow-up to #80 (batched guards). With `VICTORY_ASK_FIRST=1`, the submission's write-watch asking starts on its own thread (`victory-ask`), next to the submitting thread's planning. `guard_ahead` then ran on the submitting thread *after* that asking had been waited for. In the world of a new retail game that guarding cost 11 % of the submitting thread (~4.8 ms a frame), almost all of it `VirtualProtect` calls in `cover()` on other views of written blocks. This moves the guarding next to the asking. The asking job hands the guarding to a `wide` helper (`shadow::wide_run`) and does its own asking meanwhile. The asking only touches write-watched memory and `guard_ahead` keeps only view memory, so neither holds the other's pages (`Askings`). The submitting thread still calls `guard_ahead` at the old spot and finds the ranges published. A block written in between isn't published and gets guarded by its own refresh, which is how `guard_ahead` already behaves. - `VICTORY_GUARD_FIRST=0` guards after the wait, as before. - `VICTORY_GUARD_FIRST=ab` switches every 20 seconds and logs each switch (`guard-first switch <unix ms> on|off`), for an A/B inside one run. ## Measured RTX 4070, Ryzen 5 5600X, Series S profile, DLSS quality + frame generation, `VICTORY_SUBMIT_SPLIT=1`, `VICTORY_ASK_FIRST=1`, `VICTORY_OFF_LINE=1`. Each test is a 10-minute idle run in the world with `=ab`, pairing neighbouring 20 s windows. | per frame | before | after | |---|---|---| | asking + its wait + guarding, submitting thread | 8.9 ms | 8.1 ms | | submitting thread | — | ~0.9 ms less (23 of 26 pairs) | | frame median | — | ~0.5 ms less (18 of 26 pairs) | The gain is smaller than the guarding's cost. The kernel probably serializes part of `GetWriteWatch` and `VirtualProtect` under the process's address-space lock. A first version guarded *after* the asking on the asking thread and gained nothing (12 of 26 pairs), because the planning beside it is shorter than the asking. `cargo test -p victory-gpu --lib` passes. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
With VICTORY_ASK_FIRST the submission's write-watch asking is begun on a
thread of its own; the view memory its lists refresh was then guarded
on the submitting thread after that asking was waited for (guard_ahead,
11 % of that thread). It is now guarded on one of our helpers beside
the asking, and both beside the submitting thread's planning: the
asking is of write-watched memory and the guarding of view memory, so
neither holds the other's pages. The submitting thread still calls
guard_ahead where it did and finds the ranges published.

VICTORY_GUARD_FIRST=0 guards after the wait, as before; =ab switches
every 20 seconds and says so in the log.

Measured that way (26 neighbouring 20 s windows in the world, with
SUBMIT_SPLIT, ASK_FIRST, OFF_LINE; RTX 4070, Ryzen 5 5600X): the
asking, its wait and the guarding 8.9 -> 8.1 ms a frame, the submitting
thread ~0.9 ms less (23 of 26 pairs), frame median ~0.5 ms less (18 of
26). Guarding after the asking on the asking thread gained nothing (12
of 26): the planning beside it is shorter than the asking.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 13:10:38 +00:00
Author
Owner

@⁠mgrein on GitHub · 2026-11-30 15:27 UTC · original

A second, longer run (15 minutes, 41 pairs of neighbouring 20 s windows, same settings): frame median −0.3 ms, faster in 27 of 41 pairs. Together with the first run that's 45 of 67 pairs, so the gain is real but small, about 0.3–0.5 ms a frame.

An A/A run since then (a switch that changes nothing, toggled the same way) showed the frame-median pairing is unbiased (13 of 25), but the 5-second submitting-thread metric is too noisy to pair on (−3.6 ms with nothing changed). Please read the "submitting thread" row in the table above as indicative only.

**@⁠mgrein** on GitHub · 2026-11-30 15:27 UTC · [original](https://github.com/readmet3xt-lab/foxhound/pull/109#issuecomment-7283025818) A second, longer run (15 minutes, 41 pairs of neighbouring 20 s windows, same settings): frame median −0.3 ms, faster in 27 of 41 pairs. Together with the first run that's 45 of 67 pairs, so the gain is real but small, about 0.3–0.5 ms a frame. An A/A run since then (a switch that changes nothing, toggled the same way) showed the frame-median pairing is unbiased (13 of 25), but the 5-second submitting-thread metric is too noisy to pair on (−3.6 ms with nothing changed). Please read the "submitting thread" row in the table above as indicative only.
The last run failed in a test this change does not touch (a crash of the
victory-shader test binary, or a watch test that also fails now and then
on main); this runs the checks again.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot closed this pull request 2026-12-01 01:10:29 +00:00
Author
Owner

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

A note on why this shows as closed: GitHub closed every open pull request by itself when main's history was rewritten on 2026-12-01 (text-only changes; every commit hash changed), and they cannot be reopened. This is not a rejection.

Your change is in the batch being tested for the next release, carried over as one commit with you as its author. Nothing is needed from you now; the result will be posted here.

**@⁠readmet3xt-lab** on GitHub · 2026-12-01 01:36 UTC · [original](https://github.com/readmet3xt-lab/foxhound/pull/109#issuecomment-7297693895) A note on why this shows as closed: GitHub closed every open pull request by itself when main's history was rewritten on 2026-12-01 (text-only changes; every commit hash changed), and they cannot be reopened. This is not a rejection. Your change is in the batch being tested for the next release, carried over as one commit with you as its author. Nothing is needed from you now; the result will be posted here.

Pull request closed

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