-
Notifications
You must be signed in to change notification settings - Fork 970
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use hashbrown
in more crates (etc.)
#6938
base: trunk
Are you sure you want to change the base?
Conversation
…n hashbrown::HashSet::contains call
hashbrown
in naga
etc.hashbrown
in naga
& main wgpu
crates` etc.
hashbrown
in naga
& main wgpu
crates` etc.hashbrown
in naga
& main wgpu
crates etc.
hashbrown
in naga
& main wgpu
crates etc.hashbrown
in naga
& main wgpu
crates, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking generally good, some comments!
CHANGELOG.md
Outdated
##### Use `hashbrown` in `naga` & main `wgpu` crates | ||
|
||
Use `hashbrown` to simplify no-std support. (This may help improve performance as well.) | ||
|
||
By Brody in [#6938](https://github.com/gfx-rs/wgpu/pull/6938). | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This actually applies to more than just this section - we generally reserve the larger "Major Changes" items for breaking changes or very heavy refactors. So like when no-std lands in the whole stack, that definitely will deserve a large item. But for this, a single line is fine as this is all internal and not user facing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes total sense, I just pushed updates to compress all of this info & remove the unmeasured performance speculation. I have also squished the older hashbrown changelog update into here, out of the other place. I think this should be much cleaner.
Incidentally for small edits like this, I wouldn't mind if the reviewer wants to make the edit as a co-author if we want to save time going back-and-forth. Totally up to your best judgment on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes total sense, I just pushed updates to compress all of this info & remove the unmeasured performance speculation. I have also squished the older hashbrown changelog update into here, out of the other place. I think this should be much cleaner.
Nice
Incidentally for small edits like this, I wouldn't mind if the reviewer wants to make the edit as a co-author if we want to save time going back-and-forth. Totally up to your best judgment on this.
Yeah I do that for complex changes where explaining it is harder than just doing it :) For most cases though, commenting is easier than fully task switching to a new branch and getting out of "review" mode.
hashbrown
in naga
& main wgpu
crates, etc.hashbrown
in more crates (etc.)
/// (Similar to rustc_hash::FxHashMap but using hashbrown::HashMap instead of std::collections::HashMap.) | ||
/// To construct a new instance: `FastHashMap::default()` | ||
pub type FastHashMap<K, T> = | ||
hashbrown::HashMap<K, T, std::hash::BuildHasherDefault<rustc_hash::FxHasher>>; | ||
|
||
/// Hash set that is faster but not resilient to DoS attacks. | ||
pub type FastHashSet<K> = rustc_hash::FxHashSet<K>; | ||
/// (Similar to rustc_hash::FxHashSet but using hashbrown::HashSet instead of std::collections::HashMap.) | ||
pub type FastHashSet<K> = | ||
hashbrown::HashSet<K, std::hash::BuildHasherDefault<rustc_hash::FxHasher>>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that egui is using hashers from ahash
& nohash-hasher
, started wondering if either of these would be worth considering. I also noticed what looks like some more hashers listed in: https://github.com/RustCrypto/hashes
I am guessing we should defer consideration to the future, just wanted to note this before I forget.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah probably. Using a special hasher likely needs to be supported by benchmarks anyway. I would be interested in seeing this investigated at some point. Could you make an issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Splitting out these "controversial" changes into more bite-sized pieces is really nice to review.
# (with default-features = false to help avoid using any features that may require std::collections & support no-std build) | ||
rustc-hash = { version = "1", default-features = false } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As an aside, I think libraries should generally use default-features = false
anyway, since there is no way for a user to disable a feature if it's listed in a dependency, even if it's not actually being used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One last iteration. Might be worth setting up a hashmap on a banned type list to properly enforce this at least until we're fully checking non-std.
/// (Similar to rustc_hash::FxHashMap but using hashbrown::HashMap instead of std::collections::HashMap.) | ||
/// To construct a new instance: `FastHashMap::default()` | ||
pub type FastHashMap<K, T> = | ||
hashbrown::HashMap<K, T, std::hash::BuildHasherDefault<rustc_hash::FxHasher>>; | ||
|
||
/// Hash set that is faster but not resilient to DoS attacks. | ||
pub type FastHashSet<K> = rustc_hash::FxHashSet<K>; | ||
/// (Similar to rustc_hash::FxHashSet but using hashbrown::HashSet instead of std::collections::HashMap.) | ||
pub type FastHashSet<K> = | ||
hashbrown::HashSet<K, std::hash::BuildHasherDefault<rustc_hash::FxHasher>>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah probably. Using a special hasher likely needs to be supported by benchmarks anyway. I would be interested in seeing this investigated at some point. Could you make an issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oop wrong button sorry 😅
Co-authored-by: Connor Fitzgerald <[email protected]>
Connections
hashbrown
updates introduced in PR: Start usinghashbrown
#6925Description
hashbrown
innaga
& top-levelwgpu
cratesstd::collections::HashMap
viarustc_hash::FxHashMap
inwgpu-hal
hashbrown
in mainwgpu
cratehashbrown
indeno_webgpu
hashbrown
with default-features = false, as needed to support no-std buildPOSSIBLE API IMPACT
Exported
naga
API with these updates would be exporting types & members using HashMap & HashSet from hashbrown rather than std::collections. I think this is a crucial part of supporting no-std. I don't expect the blast radius to be very high, just wanted to point this out to avoid potential surprises for anyone./cc @bushrat011899
Testing
cargo test --all-features -p naga
cargo test --all-features -p wgpu-core
cargo test --all-features -p wgpu-hal
cargo test --all-features -p wgpu
cargo xtask test
Checklist
cargo fmt
.taplo format
.cargo clippy
. If applicable, add:--target wasm32-unknown-unknown
--target wasm32-unknown-emscripten
cargo xtask test
to run tests.CHANGELOG.md
. See simple instructions inside file.