victory-gpu: look a submission's refreshes up by pointer, not by scanning (4-13x on the merge) #1555
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1556"
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?
Imported from Marvisak/VIctory. Originally posted by pes7 on 2026-11-24T19:09:45Z.
A 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.
Imported from Marvisak/VIctory. Originally posted by pes7 on 2026-11-24T19:32:45Z.
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.
Imported from Marvisak/VIctory. Originally posted by pes7 on 2026-11-24T21:54:39Z.
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.upstream-sync referenced this pull request2026-11-25 06:02:40 +00:00
upstream-sync referenced this pull request2026-11-25 15:04:32 +00:00
upstream-sync referenced this pull request2026-11-25 17:05:14 +00:00
upstream-sync referenced this pull request2026-11-26 01:04:07 +00:00
Pull request closed