Skip to content
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

Merged
merged 1 commit into from
Jan 27, 2025

Conversation

brody4hire
Copy link
Contributor

@brody4hire brody4hire commented Jan 17, 2025

Connections

Description

  • use hashbrown in naga & top-level wgpu crates
  • completely replace indirect usage of std::collections::HashMap via rustc_hash::FxHashMap in wgpu-hal
  • use hashbrown in main wgpu crate
  • use hashbrown in deno_webgpu
  • use hashbrown with default-features = false, as needed to support no-std build
  • other minor updates

POSSIBLE 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

  • Run cargo fmt.
  • Run taplo format.
  • Run cargo clippy. If applicable, add:
    • --target wasm32-unknown-unknown
    • --target wasm32-unknown-emscripten
  • Run cargo xtask test to run tests.
  • Add change to CHANGELOG.md. See simple instructions inside file.
  • Resolve or defer XXX todo items in these updates

@brody4hire brody4hire mentioned this pull request Jan 17, 2025
9 tasks
@brody4hire brody4hire changed the title use hashbrown in naga etc. use hashbrown in naga & main wgpu crates` etc. Jan 19, 2025
@brody4hire brody4hire changed the title use hashbrown in naga & main wgpu crates` etc. use hashbrown in naga & main wgpu crates etc. Jan 19, 2025
naga/Cargo.toml Outdated Show resolved Hide resolved
@brody4hire brody4hire marked this pull request as ready for review January 19, 2025 09:51
@brody4hire brody4hire requested a review from a team as a code owner January 19, 2025 09:51
@brody4hire brody4hire requested a review from a team January 19, 2025 09:51
@brody4hire brody4hire requested a review from crowlKats as a code owner January 19, 2025 09:51
@brody4hire brody4hire changed the title use hashbrown in naga & main wgpu crates etc. use hashbrown in naga & main wgpu crates, etc. Jan 19, 2025
@brody4hire brody4hire requested a review from Wumpf January 20, 2025 04:53
Copy link
Member

@cwfitzgerald cwfitzgerald left a 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
Comment on lines 55 to 56
##### 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).

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

CHANGELOG.md Outdated Show resolved Hide resolved
naga/src/back/spv/writer.rs Outdated Show resolved Hide resolved
@brody4hire brody4hire changed the title use hashbrown in naga & main wgpu crates, etc. use hashbrown in more crates (etc.) Jan 21, 2025
Copy link
Contributor

@bushrat011899 bushrat011899 left a 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.

Cargo.toml Outdated Show resolved Hide resolved
Copy link
Member

@cwfitzgerald cwfitzgerald left a 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.

naga/src/back/spv/writer.rs Outdated Show resolved Hide resolved
naga/src/lib.rs Show resolved Hide resolved
Copy link
Member

@cwfitzgerald cwfitzgerald left a 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 😅

@cwfitzgerald cwfitzgerald self-assigned this Jan 22, 2025
@brody4hire brody4hire marked this pull request as draft January 26, 2025 20:51
Copy link
Contributor Author

@brody4hire brody4hire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I have addressed comments from @bushrat011899 & @cwfitzgerald, which have all been really helpful. I have raised #6999 to reconsider the choice of hasher for HashMap (and HashSet). I would like to see if I can fix a couple more little things here.

Cargo.toml Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
naga/fuzz/fuzz_targets/glsl_parser.rs Show resolved Hide resolved
.clippy.toml Outdated Show resolved Hide resolved
@brody4hire brody4hire marked this pull request as ready for review January 27, 2025 05:01
@brody4hire
Copy link
Contributor Author

I think this should be ready now. There may be a couple minor nits left, IMO not worth blocking this too much longer.

@nical
Copy link
Contributor

nical commented Jan 27, 2025

@brody4hire One last rebase to address the branch conflicts and this should be good to go.

Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
@brody4hire brody4hire force-pushed the use-hashbrown-further branch from 5601c2d to fd4766b Compare January 27, 2025 11:09
Copy link
Member

@cwfitzgerald cwfitzgerald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thank you!

@cwfitzgerald cwfitzgerald merged commit df54acc into gfx-rs:trunk Jan 27, 2025
31 checks passed
@brody4hire brody4hire deleted the use-hashbrown-further branch January 29, 2025 16:07
Comment on lines +53 to +56
- Use `hashbrown` to simplify no-std support. By Brody in [#6938](https://github.com/gfx-rs/wgpu/pull/6938) & [#6925](https://github.com/gfx-rs/wgpu/pull/6925).
- If you use Binding Arrays in a bind group, you may not use Dynamic Offset Buffers or Uniform Buffers in that bind group. By @cwfitzgerald in [#6811](https://github.com/gfx-rs/wgpu/pull/6811)


Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra blank line here - my bad thought I removed it d'oh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants