Merge adjacent fills and cache fill_scratch lookups (VICTORY_MERGE_FI… #473

Open
GValdezN wants to merge 1 commit from upstream-pr/473 into main
GValdezN commented 2026-12-02 15:13:37 +00:00 (Migrated from github.com)

Imported from readmet3xt-lab/foxhound. Originally posted by GValdezN on 2026-12-02T15:13:37Z.


Merge adjacent fills and cache fill_scratch lookups (VICTORY_MERGE_FILLS)

When VICTORY_MERGE_FILLS=1, fills queued in Batch::fill() are sorted by destination address before the copy loop. Adjacent entries whose source and destination are both contiguous are merged into a single copy_mapped call, reducing per-fill overhead and giving the hardware prefetcher longer sequential runs.

fill_scratch() gets a 4-entry stack-local most-recent-hit cache (always active, no switch) in front of the HashMap lookup. The four slots cover the typical working set of scratch allocations within a single list's recording; a hit avoids the hash, the probe chain, and the HashMap's pointer indirection.

Batch::fill() sits on the frame's critical path: SPLIT[7] (copies and fills) measures 4–8 ms/frame in heavy scenes. The wide path dispatches fills to wide_each workers (2–8 threads, victory-wide-N), so reducing per-entry overhead scales across threads. With VICTORY_SEND_BAR=1 (ReBAR), merged fills produce longer sequential writes over PCIe, which fill write-combining buffers more efficiently; the scatter pairs that dominate the ReBAR cost path are unaffected.

Merge is off by default (VICTORY_MERGE_FILLS=1 to enable) so it can be measured before becoming the default. The sort is stable and in-place on the existing Vec; no new allocations.

Complements #478 (prefetch in fill loop + Vec::with_capacity) — merged fills + prefetch together reduce SPLIT[7] overhead.

Test plan: cargo test -p victory-gpu (620 passed, 0 failed); cargo check -p victory-gpu clean.

🤖 Generated with Claude Code

<!-- greyfinch-sync:readmet3xt-lab/foxhound:issue:5609289906 --> Imported from [readmet3xt-lab/foxhound](https://github.com/readmet3xt-lab/foxhound/pull/473). Originally posted by [GValdezN](https://github.com/GValdezN) on 2026-12-02T15:13:37Z. --- ## Merge adjacent fills and cache fill_scratch lookups (VICTORY_MERGE_FILLS) When `VICTORY_MERGE_FILLS=1`, fills queued in `Batch::fill()` are sorted by destination address before the copy loop. Adjacent entries whose source and destination are both contiguous are merged into a single `copy_mapped` call, reducing per-fill overhead and giving the hardware prefetcher longer sequential runs. `fill_scratch()` gets a 4-entry stack-local most-recent-hit cache (always active, no switch) in front of the `HashMap` lookup. The four slots cover the typical working set of scratch allocations within a single list's recording; a hit avoids the hash, the probe chain, and the `HashMap`'s pointer indirection. `Batch::fill()` sits on the frame's critical path: SPLIT[7] (copies and fills) measures 4–8 ms/frame in heavy scenes. The wide path dispatches fills to `wide_each` workers (2–8 threads, `victory-wide-N`), so reducing per-entry overhead scales across threads. With `VICTORY_SEND_BAR=1` (ReBAR), merged fills produce longer sequential writes over PCIe, which fill write-combining buffers more efficiently; the scatter pairs that dominate the ReBAR cost path are unaffected. Merge is off by default (`VICTORY_MERGE_FILLS=1` to enable) so it can be measured before becoming the default. The sort is stable and in-place on the existing `Vec`; no new allocations. Complements #478 (prefetch in fill loop + Vec::with_capacity) — merged fills + prefetch together reduce SPLIT[7] overhead. Test plan: `cargo test -p victory-gpu` (620 passed, 0 failed); `cargo check -p victory-gpu` clean. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
tillo88 commented 2026-12-02 21:06:03 +00:00 (Migrated from github.com)

Imported from readmet3xt-lab/foxhound. Originally posted by tillo88 on 2026-12-02T21:06:03Z.


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

Measured: PR head b4468e0 merged onto release v0.8.3.3 (same code as main 7dbcdcb), with VICTORY_MERGE_FILLS=1, 2 measured runs (after a warm-up run that is not counted), against 3 runs of v0.8.3.3 without the PR, same route (~6.5 min).

run fps CPU prep ms median ms p95 ms p99 ms frames > 100 ms
release run 1 36.54 19.08 29.00 50.42 60.01 32
release run 2 36.45 20.15 28.10 38.59 45.48 13
release run 3 36.15 19.30 29.35 38.74 46.08 10
PR #473 + VICTORY_MERGE_FILLS=1 run 1 35.88 20.27 29.20 39.50 45.97 13
PR #473 + VICTORY_MERGE_FILLS=1 run 2 36.75 19.32 28.10 38.11 45.73 14

Mean fps: release 36.38, PR 36.31 (-0.2%). That is below the 2-3% we treat as a real change, so: no measurable difference on this route. Only 3 release runs so far, so the release's own spread is not established yet.

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

Note: two earlier release runs the same evening, with identical switches, were much slower for most of the route (6-9 fps average); the cause is not known yet and they are left out of the comparison above. No PR run fell into that state.

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.

<!-- greyfinch-sync:readmet3xt-lab/foxhound:comment:7358789873 --> Imported from [readmet3xt-lab/foxhound](https://github.com/readmet3xt-lab/foxhound/pull/473#issuecomment-7358789873). Originally posted by [tillo88](https://github.com/tillo88) on 2026-12-02T21:06:03Z. --- **Replay-bench measurement: no measurable difference on v0.8.3.3** Measured: PR head `b4468e0` merged onto release **v0.8.3.3** (same code as main `7dbcdcb`), with `VICTORY_MERGE_FILLS=1`, 2 measured runs (after a warm-up run that is not counted), against 3 runs of v0.8.3.3 without the PR, same route (~6.5 min). | run | fps | CPU prep ms | median ms | p95 ms | p99 ms | frames > 100 ms | |---|---|---|---|---|---|---| | release run 1 | 36.54 | 19.08 | 29.00 | 50.42 | 60.01 | 32 | | release run 2 | 36.45 | 20.15 | 28.10 | 38.59 | 45.48 | 13 | | release run 3 | 36.15 | 19.30 | 29.35 | 38.74 | 46.08 | 10 | | PR #473 + VICTORY_MERGE_FILLS=1 run 1 | 35.88 | 20.27 | 29.20 | 39.50 | 45.97 | 13 | | PR #473 + VICTORY_MERGE_FILLS=1 run 2 | 36.75 | 19.32 | 28.10 | 38.11 | 45.73 | 14 | Mean fps: release 36.38, PR 36.31 (-0.2%). That is below the 2-3% we treat as a real change, so: **no measurable difference** on this route. Only 3 release runs so far, so the release's own spread is not established yet. Crashes: none in the PR runs and none in the release runs (no host GPU failure, no device lost). Note: two earlier release runs the same evening, with identical switches, were much slower for most of the route (6-9 fps average); the cause is not known yet and they are left out of the comparison above. No PR run fell into that state. 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.
GValdezN commented 2026-12-03 01:36:29 +00:00 (Migrated from github.com)

Imported from readmet3xt-lab/foxhound. Originally posted by GValdezN on 2026-12-03T01:36:29Z.


Thanks for testing this one too, @tillo88! Makes sense that the merge-fills optimization doesn't show on this route — it benefits scenes with many fragmented small fills where the per-fill overhead adds up. The replay bench route at steady state likely has fewer, larger fills that don't fragment enough to hit the merge path often.

Would be interesting to see if it shows up on a route through a denser area with more draw calls, but no regression is the important part for now.

<!-- greyfinch-sync:readmet3xt-lab/foxhound:comment:7364533929 --> Imported from [readmet3xt-lab/foxhound](https://github.com/readmet3xt-lab/foxhound/pull/473#issuecomment-7364533929). Originally posted by [GValdezN](https://github.com/GValdezN) on 2026-12-03T01:36:29Z. --- Thanks for testing this one too, @tillo88! Makes sense that the merge-fills optimization doesn't show on this route — it benefits scenes with many fragmented small fills where the per-fill overhead adds up. The replay bench route at steady state likely has fewer, larger fills that don't fragment enough to hit the merge path often. Would be interesting to see if it shows up on a route through a denser area with more draw calls, but no regression is the important part for now.
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/473:upstream-pr/473'
git switch 'upstream-pr/473'

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/473'
git switch 'upstream-pr/473'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/473'
git switch 'upstream-pr/473'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/473'
git switch 'main'
git merge --squash 'upstream-pr/473'
git switch 'main'
git merge --ff-only 'upstream-pr/473'
git switch 'main'
git merge 'upstream-pr/473'
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
readmet3xt-lab/foxhound!473
No description provided.