perf(victory-gpu): avoid O(slots) span rebuilds and hash-order scans in heap_pass #400
No reviewers
Labels
No labels
accessibility
bloqué : binaire console
bug
chargeur
console-dll
cpu
documentation
duplicate
enhancement
good first issue
gpu
help wanted
invalid
performance
question
runtime-gdk
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/LooperSalty--AnyXboxX!400
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-400"
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?
@Lewandox on GitHub · 2026-11-26 17:15 UTC · original
Lewandox:perf/heap-pass-incremental-spans-and-scan→main· +230 −49 · 2 files · 2 commits · closed without mergingSummary
Optimizes the view-heap buffer pass (
third_party/victory/crates/victory-gpu/src/heap_pass.rsanddraw.rs::heap_buffers), whichdocs/research/stutter-2026-11-26.mdidentifies as the largest single frame-spike category (~43% of lost time across 164k–227k descriptor slots):HashMaprebuild inPicked::spans()on the default path:Picked::keepandPicked::forgetalready maintain per-copy spans andstaleflags identically for bothfull = true(default) andfull = false(VICTORY_HEAP_PASS_DIRTY=1).Picked::spans()discarded that incremental state whenself.full == trueand allocated a fresh SipHashHashMapscanning all ~227k slots every pass. Using the already-maintainedself.copiesreducesspans()fromO(slots)toO(copies)with identical results and zero temporaryHashMapallocation.Picked::keep()update & remove redundantforget()calls:draw.rs::heap_bufferscalledranges.forget(index)before every slot andPicked::keep()calledself.forget(slot)a second time — doing redundant map removals on full sweeps and markingcopy.stale = true(forcing full re-scans of every slot belonging to that host copy) even when a re-checked slot still referenced the same copy with an unchanged or wider span.Picked::keep()now updates slots in place when the host copy key is unchanged, markingcopy.stale = trueonly when a slot actually shrinks off a copy boundary, anddraw.rscallsranges.forget(index)only on early-exit paths where the slot no longer maps to a buffer view.slotsandorphansinBTreeMapsoPicked::plan()scans title descriptor heap memory in ascending slot order (sequential prefetching instead of random hash-bucket order) and accepts sorted full-sweep slot lists (HostHeap::buffer_slots) without hash-table rehashing.HashSet<u32>allocation inPicked::plan()with in-placeVec<u32>+sort_unstable+dedup.IntBuildHasher) forcopies,Copy::slots, andby_entryinstead of SipHash-1-3 onu32/usizekeys.full = trueandfull = falseproduce identical spans across adds, in-place updates, expansions, boundary shrinks, copy switches, and removals.copy.stale, while boundary shrinks do and recompute exact spans.plan()deduplicates slots appearing viachanged,forgotten, and record-change scans in ascending order.Verification
cargo test -p victory-gpu --lib heap_pass::tests(default and--features diagnostics)cargo xtask policyinsidethird_party/victory@LooperSalty on GitHub · 2026-11-26 18:27 UTC · original
Thanks for this one. Holding it for now: it changes the default path (
spans()now readscopiesinstead of rebuilding fromslots), and the review found three issues:heap_pass.rs, new fast path inkeep:note_entryonly runs whenold_record != record.plan()removes each forgotten entry fromby_entry; when the slot is seen again with the same record it is not registered again, so the next release of that entry is missed. This regressesVICTORY_HEAP_PASS_DIRTY=1, where the old code always re-registered. Fix: always callnote_entry.orphan(early return when the record is unchanged). Same fix.IntHasher::write_usizeis(h ^ i) * C. The keys ofcopiesareArcaddresses, aligned, so their low bits are zero and so are the hash's low bits; hashbrown indexes with those bits, so ~4,000 copies collide heavily. Mix the high bits in (rotate_left, or a fold ofh >> 32).slotsas aBTreeMapalso makeskeep/forgetO(log n) over ~227,000 slots: a frame-time measurement before and after would help. We are measuring it in game on our side too.🤖 Generated with Claude Code
@Lewandox on GitHub · 2026-11-26 18:56 UTC · original
Thanks for the detailed review — all three issues are now fixed:
keepfast path now unconditionally callsself.note_entry(slot, entry)even whenold_record == record, so entries drained byplan()are always re-registered underVICTORY_HEAP_PASS_DIRTY=1.orphanfast path likewise callsself.note_entry(slot, entry)before returning whenself.orphans.get(&slot) == Some(&record).IntHashernow applies a full 64-bit avalanche mix (mix64infinish(), plusrotate_left(5)on writes) so alignedArcpointers distribute uniformly across both low bucket bits and top H2 tag bits inhashbrown.Added regression tests for both (
forgotten_entry_re_registers_on_repeated_keep_and_orphan_with_same_recordandint_hasher_avalanche_mixes_aligned_pointer_low_bits). Verified withcargo test -p victory-gpu --lib heap_pass::tests(default and--features diagnostics) +cargo xtask policy.@Lewandox on GitHub · 2026-11-26 19:15 UTC · original
Closing as obsolete after #409 (\heap_pass.rs\ was removed in the combined base). Keeping the PR queue clean.
Pull request closed