Guard the write summary against partially published journal batches #528

Open
github-bot wants to merge 4 commits from github-bot/gh-528 into main AGit
Owner

@⁠tavochivix on GitHub · 2026-12-03 02:16 UTC · original
tavochivix:codex/pr472-journal-publication → main · +183 −4 · 2 files · 4 commits · open

This builds on @⁠GValdezN's write-summary optimization in #472. The branch keeps the original commit (3e28da6) and targets main so maintainers can review the combined change or take the follow-up commits onto #472. Compare only the follow-up changes.

How an alias can be reported clean

  1. Two virtual addresses refer to the same physical page. A write through a side view changes the shared bytes while the guarded alias stays published.
  2. landed_beside takes the journal's exclusive lock and records the affected addresses in one batch. Before it updates the alias's summary bucket, the lock-free reader can still see the old bucket value.
  3. The reader can report “unchanged” and skip a copy. A reader using the locked journal at that point waits for the batch and sees the newer write.

Updating the bucket earlier inside each individual Journal::note would still leave a gap between notes for different aliases. The unit that needs to be observed consistently is the entire writer transaction. The existing order in which a landing writes the bytes and then records them is preserved.

What changes

  • 47ee1bf brackets every mutation through journal_mut with an odd/even sequence. The reader samples the sequence around the publication and bucket checks. It accepts a clean result only if both samples match and are even. Otherwise the caller uses the existing locked path. Writers hold the exclusive lock through both sequence updates. If a writer unwinds, the fast path stays disabled.
  • 430c86c removes the full copied.pages minimum scan that #472 added after an exact hit on shadows larger than 64 pages. A one-page query could repeatedly scan the entire shadow while a different, older page kept the minimum unchanged. The existing conservative lower bound remains valid.
  • 8b83336 strengthens the active-writer regression test. A clean published alias is the positive control. The same alias must decline the fast path while the writer is active, even with a threshold high enough for every bucket to pass. A second test covers a writer that starts and finishes during a scan, leaving both sequence samples even.

Reproducing the regression on Windows

From the PR checkout, run the focused tests against generated memory:

cargo test --locked -p victory-gpu --lib watch::tests::published_alias_defers_to_an_active_journal_writer -- --exact
cargo test --locked -p victory-gpu --lib watch::tests::summary_rejects_a_writer_that_finishes_during_the_scan -- --exact
cargo test --locked -p victory-gpu --lib watch::tests::what_is_put_in_beside_the_guards_is_told_at_every_view -- --exact

For the before/after comparison, copy just the first test function into the same watch::tests module at #472's head (3e28da6) and run the first command again. On Windows I verified that this exact test fails on 3e28da6 at the assertion with the writer held and passes on the submitted head 8b83336. In a separate two-thread local test, pausing publication during an actual alias landing produced a false clean answer in 50/50 trials on #472 and 0/50 on the corrected build.

At the submitted head, local Windows checks passed:

  • cargo xtask policy
  • cargo clippy --workspace --all-targets --locked -- -D warnings
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings
  • cargo test --workspace --locked — 1,360 passed, 50 ignored, including 622 passed in victory-gpu.
Measurements on a Ryzen 5 5600X and RTX 5070 Ti

A synthetic narrow-check benchmark used a large shadow with mixed write epochs. The requested page was already up to date, while an older page kept the whole-shadow minimum below it. At 16,384 tracked pages, the median cost of that one-page check was 8.77 µs on #472 and 0.020 µs with the fix. This measures the check in isolation.

Six release runs used the same automatic 3D camera sequence, two per build, in forward and reverse order. Each started with a fresh copy of the same save and warmed FoxHound cache. The driver cache was shared. Settings were Series X, 4K, frame generation off, no title profile, and default journal batching. The host was Windows 11, NVIDIA driver 610.88, RTX 5070 Ti 16 GB, Ryzen 5 5600X. We sampled a 60-second window starting eight seconds after the first interval with at least 30 blocks landed beside guards per frame. Only complete frame-time log intervals were included.

Build FPS by run Pooled FPS Frames >50 ms / 1,000 Frames >100 ms / 1,000
Base 7dbcdcb 18.30, 21.44 19.87 345.7 42.6
#472 3e28da6 18.68, 19.50 19.09 325.8 43.6
Corrected 430c86c 19.68, 21.52 20.60 374.5 39.1

The final commit changes tests only. In the last 30 seconds, pooled FPS was 25.34, 25.82 and 25.57, respectively. Run-to-run variation and mixed frame-time results leave the overall performance effect inconclusive.

In a separate instrumented run, 186 of 109,067 summary queries started during a writer transaction, and two more rejected a possible clean result because the sequence changed during the scan. This measures how often the guard intervened. The test did not identify a specific visual artifact.

**@⁠tavochivix** on GitHub · 2026-12-03 02:16 UTC · [original](https://github.com/readmet3xt-lab/foxhound/pull/528) `tavochivix:codex/pr472-journal-publication` → `main` · +183 −4 · 2 files · 4 commits · open This builds on @⁠GValdezN's write-summary optimization in #472. The branch keeps the original commit (`3e28da6`) and targets `main` so maintainers can review the combined change or take the follow-up commits onto #472. [Compare only the follow-up changes](https://github.com/tavochivix/foxhound/compare/3e28da6723725529222598f6662dbcf1c3f5e52b...8b83336742cb20c4e1110f2a0766711dbf8a8544). ## How an alias can be reported clean 1. Two virtual addresses refer to the same physical page. A write through a side view changes the shared bytes while the guarded alias stays published. 2. `landed_beside` takes the journal's exclusive lock and records the affected addresses in one batch. Before it updates the alias's summary bucket, the lock-free reader can still see the old bucket value. 3. The reader can report “unchanged” and skip a copy. A reader using the locked journal at that point waits for the batch and sees the newer write. Updating the bucket earlier inside each individual `Journal::note` would still leave a gap between notes for different aliases. The unit that needs to be observed consistently is the entire writer transaction. The existing order in which a landing writes the bytes and then records them is preserved. ## What changes - `47ee1bf` brackets every mutation through `journal_mut` with an odd/even sequence. The reader samples the sequence around the publication and bucket checks. It accepts a clean result only if both samples match and are even. Otherwise the caller uses the existing locked path. Writers hold the exclusive lock through both sequence updates. If a writer unwinds, the fast path stays disabled. - `430c86c` removes the full `copied.pages` minimum scan that #472 added after an exact hit on shadows larger than 64 pages. A one-page query could repeatedly scan the entire shadow while a different, older page kept the minimum unchanged. The existing conservative lower bound remains valid. - `8b83336` strengthens the active-writer regression test. A clean published alias is the positive control. The same alias must decline the fast path while the writer is active, even with a threshold high enough for every bucket to pass. A second test covers a writer that starts **and finishes** during a scan, leaving both sequence samples even. ## Reproducing the regression on Windows From the PR checkout, run the focused tests against generated memory: ```powershell cargo test --locked -p victory-gpu --lib watch::tests::published_alias_defers_to_an_active_journal_writer -- --exact cargo test --locked -p victory-gpu --lib watch::tests::summary_rejects_a_writer_that_finishes_during_the_scan -- --exact cargo test --locked -p victory-gpu --lib watch::tests::what_is_put_in_beside_the_guards_is_told_at_every_view -- --exact ``` For the before/after comparison, copy just the first test function into the same `watch::tests` module at #472's head (`3e28da6`) and run the first command again. On Windows I verified that this exact test fails on `3e28da6` at the assertion with the writer held and passes on the submitted head `8b83336`. In a separate two-thread local test, pausing publication during an actual alias landing produced a false clean answer in **50/50** trials on #472 and **0/50** on the corrected build. At the submitted head, local Windows checks passed: - `cargo xtask policy` - `cargo clippy --workspace --all-targets --locked -- -D warnings` - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings` - `cargo test --workspace --locked` — 1,360 passed, 50 ignored, including 622 passed in `victory-gpu`. <details> <summary>Measurements on a Ryzen 5 5600X and RTX 5070 Ti</summary> A synthetic narrow-check benchmark used a large shadow with mixed write epochs. The requested page was already up to date, while an older page kept the whole-shadow minimum below it. At 16,384 tracked pages, the median cost of that one-page check was **8.77 µs** on #472 and **0.020 µs** with the fix. This measures the check in isolation. Six release runs used the same automatic 3D camera sequence, two per build, in forward and reverse order. Each started with a fresh copy of the same save and warmed FoxHound cache. The driver cache was shared. Settings were Series X, 4K, frame generation off, no title profile, and default journal batching. The host was Windows 11, NVIDIA driver 610.88, RTX 5070 Ti 16 GB, Ryzen 5 5600X. We sampled a 60-second window starting eight seconds after the first interval with at least 30 blocks landed beside guards per frame. Only complete frame-time log intervals were included. | Build | FPS by run | Pooled FPS | Frames >50 ms / 1,000 | Frames >100 ms / 1,000 | | --- | --- | ---: | ---: | ---: | | Base `7dbcdcb` | 18.30, 21.44 | 19.87 | 345.7 | 42.6 | | #472 `3e28da6` | 18.68, 19.50 | 19.09 | 325.8 | 43.6 | | Corrected `430c86c` | 19.68, 21.52 | 20.60 | 374.5 | 39.1 | The final commit changes tests only. In the last 30 seconds, pooled FPS was 25.34, 25.82 and 25.57, respectively. Run-to-run variation and mixed frame-time results leave the overall performance effect inconclusive. In a separate instrumented run, 186 of 109,067 summary queries started during a writer transaction, and two more rejected a possible clean result because the sequence changed during the scan. This measures how often the guard intervened. The test did not identify a specific visual artifact. </details>
A static array of 16,384 AtomicU64 (128 KiB) records the highest asking
at which each hash bucket was written.  Shadow::nothing_new() checks
the summary before taking the JOURNAL RwLock: when every bucket in the
range is at or below the copy's min_taken, the copy is known unchanged
without any lock.  With ~0.4% of pages dirty per frame, ~91% of
nothing_new() calls now skip the lock entirely.

A second small change refreshes min_taken on the slow path for large
buffers (>64 pages) so the fast path activates on subsequent frames.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-03 02:20:58 +00:00
Author
Owner

@⁠tillo88 on GitHub · 2026-12-04 00:47 UTC · original

Replay-bench measurement on v0.8.3.5: no measurable difference

Measured: PR head 8b83336 merged onto release v0.8.3.5 (5e44415), 2 measured runs (after a warm-up run that is not counted), against 5 runs of v0.8.3.5 without the PR (fps range 36.45-37.23), same route (~6.5 min).

run fps CPU prep ms median ms p95 ms p99 ms frames > 100 ms
release run 1 36.47 19.38 28.50 39.21 46.42 16
release run 2 36.45 19.10 28.70 39.06 45.68 17
release run 3 37.23 18.49 27.80 38.21 45.59 14
release run 4 36.53 19.26 28.25 39.23 45.32 12
release run 5 37.10 18.65 28.15 38.25 44.78 13
release, mean of 5 36.76 18.98 28.28 38.79 45.56 14.4
PR #528 run 1 37.15 19.19 28.40 38.11 48.67 10
PR #528 run 2 36.63 19.53 28.70 38.64 45.86 14

Mean fps: release 36.76, PR 36.89 (+0.4%): no measurable difference in frame rate. CPU prep, median and p95 frame times are within the release's run-to-run spread; run 1 had the highest p99 of all seven runs (48.67 ms) and the fewest frames over 100 ms (10), run 2 is inside the release's range on both. The bench only shows the cost side of this change; it cannot tell whether partially published journal batches happen on this route.

Crashes: none in the PR runs and none in the release runs (no host GPU failure, no device lost).

Config: RTX 5070 Ti 16 GB, Ryzen 7 9800X3D, 32 GB, Windows 11; default play-foxhound.ps1 settings (Series X profile, 1440p, DLSS balanced, no frame generation), fullscreen, no frame cap.

Measured unattended on a replay bench (same save, recorded controller input); numbers and text prepared with Claude.

**@⁠tillo88** on GitHub · 2026-12-04 00:47 UTC · [original](https://github.com/readmet3xt-lab/foxhound/pull/528#issuecomment-7397159593) **Replay-bench measurement on v0.8.3.5: no measurable difference** Measured: PR head `8b83336` merged onto release **v0.8.3.5** (`5e44415`), 2 measured runs (after a warm-up run that is not counted), against 5 runs of v0.8.3.5 without the PR (fps range 36.45-37.23), same route (~6.5 min). | run | fps | CPU prep ms | median ms | p95 ms | p99 ms | frames > 100 ms | |---|---|---|---|---|---|---| | release run 1 | 36.47 | 19.38 | 28.50 | 39.21 | 46.42 | 16 | | release run 2 | 36.45 | 19.10 | 28.70 | 39.06 | 45.68 | 17 | | release run 3 | 37.23 | 18.49 | 27.80 | 38.21 | 45.59 | 14 | | release run 4 | 36.53 | 19.26 | 28.25 | 39.23 | 45.32 | 12 | | release run 5 | 37.10 | 18.65 | 28.15 | 38.25 | 44.78 | 13 | | **release, mean of 5** | **36.76** | **18.98** | **28.28** | **38.79** | **45.56** | **14.4** | | PR #528 run 1 | 37.15 | 19.19 | 28.40 | 38.11 | 48.67 | 10 | | PR #528 run 2 | 36.63 | 19.53 | 28.70 | 38.64 | 45.86 | 14 | Mean fps: release 36.76, PR 36.89 (+0.4%): **no measurable difference** in frame rate. CPU prep, median and p95 frame times are within the release's run-to-run spread; run 1 had the highest p99 of all seven runs (48.67 ms) and the fewest frames over 100 ms (10), run 2 is inside the release's range on both. The bench only shows the cost side of this change; it cannot tell whether partially published journal batches happen on this route. Crashes: none in the PR runs and none in the release runs (no host GPU failure, no device lost). Config: RTX 5070 Ti 16 GB, Ryzen 7 9800X3D, 32 GB, Windows 11; default `play-foxhound.ps1` settings (Series X profile, 1440p, DLSS balanced, no frame generation), fullscreen, no frame cap. Measured unattended on a replay bench (same save, recorded controller input); numbers and text prepared with Claude.
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/528/head:github-bot/gh-528'
git switch 'github-bot/gh-528'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-528'
git switch 'github-bot/gh-528'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-528'
git switch 'github-bot/gh-528'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-528'
git switch 'main'
git merge --squash 'github-bot/gh-528'
git switch 'main'
git merge --ff-only 'github-bot/gh-528'
git switch 'main'
git merge 'github-bot/gh-528'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.