victory-gpu: look a submission's refreshes up by pointer, not by scanning (4-13x on the merge) #1556
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!1556
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1556/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@pes7 on GitHub · 2026-11-24 19:09 UTC · original
pes7:perf/batch-refresh-index→main· +72 −7 · 1 files · 1 commits · closed without mergingA submission's refreshes are merged with a linear scan per refresh, so a frame's preparation is quadratic in the number of buffers. An index makes it constant: 4.4x at 250 buffers, 13x at 1000, and 33 000 refreshes per submission is what #400 measures.
Batch::addkeeps one entry per shadow buffer and folds each new range into it. It found that entry withrefreshes.iter_mut().find(|(s, ..)| Arc::ptr_eq(s, shadow))- a scan over every buffer already seen in the submission - and it is called once perStep::Refresh, which #400 counts at 33-35 k per world frame.What changes
BatchkeepsHashMap<usize, usize>fromArc::as_ptrto the entry's position. Lookup is a hash of one word instead of a scan; the entry still holds a clone of theArc, so the allocation the key names stays alive until the entry is drained, and addresses cannot be reused under it.flush()clears the index with the vector.Measured
New
#[ignore]d test in thebatchmodule, stand-in buffers of one word each (the comparison is a pointer either way, so the shape is the real one), 33 000 refreshes over the same 50/250/1000 buffers, best of 7:Honest about the small end: below about 75 buffers the scan is cheaper than a hash, by 0.05 ms. Above it the scan grows linearly and the index does not. #400 and #783 report a world submission refreshing tens of thousands of ranges over buffers that include "several views into one 174 MB block, among others", so if a submission touches more than ~75 distinct buffers this is 0.7-2.9 ms of every frame's preparation; if it touches fewer, it costs 0.05 ms. A one-line counter of
batch.refreshes.len()in thecopystatline would settle which - happy to add it if you want the number before deciding.Run it with:
Correctness
The merge result is identical: same entry, same
min/maxfold, entries still drained in insertion order.cargo test --workspace --locked, both clippy configurations with-D warnings,cargo xtask policy.No game data used.
@pes7 on GitHub · 2026-11-24 19:32 UTC · original
Note for whoever reviews this against #776: both touch
Batchin this file. #776's branch changestitle_written/the watch sweep; this changesaddandflush. Different lines, same struct - whichever lands second needs a trivial rebase, and I am happy to do it for this side.They also stack: #776 cuts the number of askings, this cuts the per-refresh merge. Neither changes the other's numbers.
@pes7 on GitHub · 2026-11-24 21:54 UTC · original
Closing this as superseded by
main:Batch::addno longer scans. Upstream now keepspending(where each copy's refresh is inrefreshes, byArc::as_ptr) andcurrent(the range each copy was brought up to date to since the last title write), so both the quadratic lookup and the repeated-range dedupe this PR proposed are already there:For the record, so the measurement is not lost: on a synthetic world-sized batch (250 buffers, then 1 000) the merge went from 4.4x to 13x faster than the scan, and the same numbers would have applied to a
Batchlike the one this was written against.Thanks to whoever landed it - it is the same fix, done there first. Nothing else of mine depends on this PR; #1656 (the copy-back side) is being rebased on top of the new
Batch.Pull request closed