perf(gpu): use FxHash HashMap in descriptor VIEWS table #506
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/lobomfz--VIctory-xmem!506
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-506"
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?
@Not4Eric on GitHub · 2026-12-04 20:24 UTC · original
Not4Eric:perf/descriptor-fxhash-views→main· +44 −8 · 1 files · 1 commits · merged 2026-12-05 17:28 UTCWhat this does
Replaces the
BTreeMapindices (index,by_resource,shape_index) insidevictory_gpu::descriptor::Viewswith aHashMapusing a small non-cryptographicFxHash-style hasher (ViewHasher, zero new crate dependencies) and derivesHashonView. Lookup and insertion inVIEWSare now O(1) instead of O(log N) tree traversals under theVIEWSRwLock.Checks
View,ViewHasher, andViewsincrates/victory-gpu/src/descriptor.rs.descriptor::unit tests cover view deduplication, lookup, and resource teardown; no behavioural bug existed before to fail a test.perf/descriptor-tls-hit(separate regions ofdescriptor.rs).cargo xtask policypassed (359 files ok); no fork-only files, configs, or build outputs.Verified
cargo xtask policy—359 files okPKG=victory-gpu ./build.sh test --lib -- descriptor:: --skip views_die_with_their_resource --test-threads=1(Proton Wine on Linux, RX 9070 XT) —40 passed; 0 failed, 0 warningsCost
Negligible:
HashMapbucket overhead vsBTreeMapnode allocations forVIEWSentries; 0 new warnings.AI-assisted: yes
@Kal0s-design on GitHub · 2026-12-04 22:34 UTC · original
Checked
9fb6941on native Windows (didn't run the game). Merges clean on current main and alongside #505. victory-gpu lib tests show the same failures as main (indirect host_list x2, pipeline library loads x2, and the flaky watch test that also fails on main when run alone) and clippy with and without diagnostics adds nothing. No new dependency, and nothing iterates index, by_resource or shape_index, so the order change doesn't matter.One thing worth a look. finish() (descriptor.rs:604) returns the raw multiply, so a key whose low bits are zero keeps zero low bits in the hash, and those are the bits HashMap picks the bucket with. That hits by_resource, whose keys are Resource addresses. A throwaway test allocating 20k blocks of the Resource layout under the crate's allocator gave about 90% of them 256-byte aligned (fresh and mostly sequential, so if anything kinder than a long game session). In a small standalone bench on those addresses, 20k keys, lookup went 27 ns with the BTreeMap on main, 11 ns with this PR, 6.5 ns with plain std SipHash, and 1.5 ns with the same hasher plus rotate_left(26) in finish, which is what rustc-hash 2 does for exactly this reason. With synthetic 4 KiB aligned keys it gets worse than the tree (133 vs 50 ns). So it's still a win over main as is, but a rotate in finish is one line and removes the cliff. index is less affected since the enum tag gets mixed in first, though Shader(r, None) at 20k was still 25 ns vs 14 ns for Shader(r, Some(..)).
Two small things. ViewHasher was inserted between the long "Every distinct view in use" comment and struct Views, so that doc now sits on ViewHasher (descriptor.rs:593) and Views has none. And views_kept still estimates the index as a tree ("a tree node" and the 3/2 factor at descriptor.rs:940 and 963-965), diagnostics only.
AI-assisted: yes
9fb6941e8eto0ae5ab4435@Not4Eric on GitHub · 2026-12-05 00:00 UTC · original
Thank you so much for helping, I'm not the best at this and I'm heavily relying on AI to even do this
Pushed updates addressing your review:
self.0.rotate_left(26)fromViewHasher::finish().ViewHasherandViewMapabovestruct Views's doc comment block so the comment stays attached toViews.views_kept()'s comment from "a tree node" to "a hash table bucket".@Kal0s-design on GitHub · 2026-12-05 00:48 UTC · original
Re-checked
0ae5ab4on native Windows (didn't run the game).All three are fixed. finish() now rotates (descriptor.rs:584), the Views doc is back on struct Views (608-629), and the views_kept comment says hash table bucket. In a standalone bench with 20k synthetic evenly spaced keys, lookups went from 6.0 to 1.7 ns at 256 byte spacing and from 146 to 2.8 ns at 4 KiB, so the cliff is gone. The
* 3 / 2factor at descriptor.rs:963 and 965 is still there, diagnostics only.Full victory-gpu lib is 352 passed / 5 failed, the same known native failures as before, and clippy with and without diagnostics shows nothing new.
Looks good to me.
AI-assisted: yes