-
-
Notifications
You must be signed in to change notification settings - Fork 18
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
feat: add feature to use rustc-hash #423
Conversation
639ca7a
to
cf81614
Compare
Interesting idea! I'll have to read up a bit on Thanks for opening the PR. Leave it with me, I've got the ball and I'll carry it forward from here. |
The ahash comparison contains a good overview of
I have issues with Another reason I dislike But I don't thin either of the previous issues apply to this case. |
I agree on version detection being an issue. The perf boost is nice but this being a FOSS project, it's really sensitive to maintainability problems and I don't think we should knowingly add something that creates substantial new maintenance burden. So I wouldn't expose an You mentioned looking into switching to an |
Of course! I'll check it out! |
We use `rustc-hash::FxHashMap/Set` on src/visibility_tracker.rs this is an implementation detail as AFAIK all types there are `pub(crate)` so we never return an `FxHashMap` or `FxHashSet` on a public interface. This bring a nice perf increase: ```console ❯ cargo criterion --bench indexed_crate IndexedCrate/new(aws-sdk-ec2) time: [1.3474 s 1.3506 s 1.3537 s] change: [+4.4411% +4.8278% +5.2381%] (p = 0.00 < 0.05) Performance has regressed. ❯ cargo criterion --bench indexed_crate --features rustc-hash IndexedCrate/new(aws-sdk-ec2) time: [1.1555 s 1.1561 s 1.1567 s] change: [-14.603% -14.405% -14.192%] (p = 0.00 < 0.05) Performance has improved. ❯ cargo criterion --bench indexed_crate --features rayon IndexedCrate/new(aws-sdk-ec2) time: [577.26 ms 578.45 ms 579.70 ms] change: [-50.083% -49.964% -49.852%] (p = 0.00 < 0.05) Performance has improved. ❯ cargo criterion --bench indexed_crate --features rayon,rustc-hash IndexedCrate/new(aws-sdk-ec2) time: [486.94 ms 488.49 ms 490.13 ms] change: [-15.862% -15.552% -15.212%] (p = 0.00 < 0.05) Performance has improved. ```
It does give an improvement, but I had to use unsafe to transmute (numbers from a different machine than the usual one)
I had to use unsafe for the #[repr(transparent)]
struct IdRef(str);
impl std::borrow::Borrow<IdRef> for Id {
fn borrow(&self) -> &IdRef {
// Safety: &IdRef has the same layout and lifetime as &str (because it is repr(transparent))
unsafe { std::mem::transmute(self.0.as_str()) }
}
}
struct IdType<T: ?Sized>(pub T);
type Id = IdType<Box<str>>;
type IdRef = IdType<str>;
fn coerce() {
let id: Id = IdType("type".into());
let id_ref: &IdRef = &id;
} This has the added benefit of |
cf81614
to
8f4336a
Compare
This reduces the size of `Id` from 24 bytes to 16 bytes on 64-bit systems, and from 12 bytes to 8 bytes in 32-bit systems. It also adds an `IdRef` type that we can use instead of a `&Id`, this avoids a double indirection (`&str` vs `&String`). In `trustfall-rustdoc-adapter` we see a [7% perf improvement][1] when using `&IdRef` instead of `&Id`. Sadly, AFAIK, there is no way to safely coerce `Id(Box<str>)` to `&IdRef(str)` so we need to do an unsafe `std::mem::transmute(&str) -> &IdRef`. [1]: obi1kenobi/trustfall-rustdoc-adapter#423 (comment)
I'll ask the If you have a second, another set of numbers that would be super useful is whether/how the runtime of the entire |
This reduces the size of `Id` from 24 bytes to 16 bytes on 64-bit systems, and from 12 bytes to 8 bytes in 32-bit systems. It also adds an `IdRef` type that we can use instead of a `&Id`, this avoids a double indirection (`&str` vs `&String`). In `trustfall-rustdoc-adapter` we see a [7% perf improvement][1] when using `&IdRef` instead of `&Id`. Sadly, AFAIK, there is no way to safely coerce `Id(Box<str>)` to `&IdRef(str)` so we need to do an unsafe `std::mem::transmute(&str) -> &IdRef`. [1]: obi1kenobi/trustfall-rustdoc-adapter#423 (comment)
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've done some reading, and I think this is a good change — let's do it!
We use `rustc-hash::FxHashMap/Set` on src/visibility_tracker.rs this is an implementation detail as AFAIK all types there are `pub(crate)` so we never return an `FxHashMap` or `FxHashSet` on a public interface. This bring a nice perf increase: ```console ❯ cargo criterion --bench indexed_crate IndexedCrate/new(aws-sdk-ec2) time: [1.3474 s 1.3506 s 1.3537 s] change: [+4.4411% +4.8278% +5.2381%] (p = 0.00 < 0.05) Performance has regressed. ❯ cargo criterion --bench indexed_crate --features rustc-hash IndexedCrate/new(aws-sdk-ec2) time: [1.1555 s 1.1561 s 1.1567 s] change: [-14.603% -14.405% -14.192%] (p = 0.00 < 0.05) Performance has improved. ❯ cargo criterion --bench indexed_crate --features rayon IndexedCrate/new(aws-sdk-ec2) time: [577.26 ms 578.45 ms 579.70 ms] change: [-50.083% -49.964% -49.852%] (p = 0.00 < 0.05) Performance has improved. ❯ cargo criterion --bench indexed_crate --features rayon,rustc-hash IndexedCrate/new(aws-sdk-ec2) time: [486.94 ms 488.49 ms 490.13 ms] change: [-15.862% -15.552% -15.212%] (p = 0.00 < 0.05) Performance has improved. ``` Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>
We use `rustc-hash::FxHashMap/Set` on src/visibility_tracker.rs this is an implementation detail as AFAIK all types there are `pub(crate)` so we never return an `FxHashMap` or `FxHashSet` on a public interface. This bring a nice perf increase: ```console ❯ cargo criterion --bench indexed_crate IndexedCrate/new(aws-sdk-ec2) time: [1.3474 s 1.3506 s 1.3537 s] change: [+4.4411% +4.8278% +5.2381%] (p = 0.00 < 0.05) Performance has regressed. ❯ cargo criterion --bench indexed_crate --features rustc-hash IndexedCrate/new(aws-sdk-ec2) time: [1.1555 s 1.1561 s 1.1567 s] change: [-14.603% -14.405% -14.192%] (p = 0.00 < 0.05) Performance has improved. ❯ cargo criterion --bench indexed_crate --features rayon IndexedCrate/new(aws-sdk-ec2) time: [577.26 ms 578.45 ms 579.70 ms] change: [-50.083% -49.964% -49.852%] (p = 0.00 < 0.05) Performance has improved. ❯ cargo criterion --bench indexed_crate --features rayon,rustc-hash IndexedCrate/new(aws-sdk-ec2) time: [486.94 ms 488.49 ms 490.13 ms] change: [-15.862% -15.552% -15.212%] (p = 0.00 < 0.05) Performance has improved. ``` Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>
We use `rustc-hash::FxHashMap/Set` on src/visibility_tracker.rs this is an implementation detail as AFAIK all types there are `pub(crate)` so we never return an `FxHashMap` or `FxHashSet` on a public interface. This bring a nice perf increase: ```console ❯ cargo criterion --bench indexed_crate IndexedCrate/new(aws-sdk-ec2) time: [1.3474 s 1.3506 s 1.3537 s] change: [+4.4411% +4.8278% +5.2381%] (p = 0.00 < 0.05) Performance has regressed. ❯ cargo criterion --bench indexed_crate --features rustc-hash IndexedCrate/new(aws-sdk-ec2) time: [1.1555 s 1.1561 s 1.1567 s] change: [-14.603% -14.405% -14.192%] (p = 0.00 < 0.05) Performance has improved. ❯ cargo criterion --bench indexed_crate --features rayon IndexedCrate/new(aws-sdk-ec2) time: [577.26 ms 578.45 ms 579.70 ms] change: [-50.083% -49.964% -49.852%] (p = 0.00 < 0.05) Performance has improved. ❯ cargo criterion --bench indexed_crate --features rayon,rustc-hash IndexedCrate/new(aws-sdk-ec2) time: [486.94 ms 488.49 ms 490.13 ms] change: [-15.862% -15.552% -15.212%] (p = 0.00 < 0.05) Performance has improved. ``` Co-authored-by: Jalil David Salamé Messina <60845989+jalil-salame@users.noreply.github.com>
We use `rustc-hash::FxHashMap/Set` on src/visibility_tracker.rs this is an implementation detail as AFAIK all types there are `pub(crate)` so we never return an `FxHashMap` or `FxHashSet` on a public interface. This bring a nice perf increase: ```console ❯ cargo criterion --bench indexed_crate IndexedCrate/new(aws-sdk-ec2) time: [1.3474 s 1.3506 s 1.3537 s] change: [+4.4411% +4.8278% +5.2381%] (p = 0.00 < 0.05) Performance has regressed. ❯ cargo criterion --bench indexed_crate --features rustc-hash IndexedCrate/new(aws-sdk-ec2) time: [1.1555 s 1.1561 s 1.1567 s] change: [-14.603% -14.405% -14.192%] (p = 0.00 < 0.05) Performance has improved. ❯ cargo criterion --bench indexed_crate --features rayon IndexedCrate/new(aws-sdk-ec2) time: [577.26 ms 578.45 ms 579.70 ms] change: [-50.083% -49.964% -49.852%] (p = 0.00 < 0.05) Performance has improved. ❯ cargo criterion --bench indexed_crate --features rayon,rustc-hash IndexedCrate/new(aws-sdk-ec2) time: [486.94 ms 488.49 ms 490.13 ms] change: [-15.862% -15.552% -15.212%] (p = 0.00 < 0.05) Performance has improved. ``` Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>
We use `rustc-hash::FxHashMap/Set` on src/visibility_tracker.rs this is an implementation detail as AFAIK all types there are `pub(crate)` so we never return an `FxHashMap` or `FxHashSet` on a public interface. This bring a nice perf increase: ```console ❯ cargo criterion --bench indexed_crate IndexedCrate/new(aws-sdk-ec2) time: [1.3474 s 1.3506 s 1.3537 s] change: [+4.4411% +4.8278% +5.2381%] (p = 0.00 < 0.05) Performance has regressed. ❯ cargo criterion --bench indexed_crate --features rustc-hash IndexedCrate/new(aws-sdk-ec2) time: [1.1555 s 1.1561 s 1.1567 s] change: [-14.603% -14.405% -14.192%] (p = 0.00 < 0.05) Performance has improved. ❯ cargo criterion --bench indexed_crate --features rayon IndexedCrate/new(aws-sdk-ec2) time: [577.26 ms 578.45 ms 579.70 ms] change: [-50.083% -49.964% -49.852%] (p = 0.00 < 0.05) Performance has improved. ❯ cargo criterion --bench indexed_crate --features rayon,rustc-hash IndexedCrate/new(aws-sdk-ec2) time: [486.94 ms 488.49 ms 490.13 ms] change: [-15.862% -15.552% -15.212%] (p = 0.00 < 0.05) Performance has improved. ``` Co-authored-by: Jalil David Salamé Messina <60845989+jalil-salame@users.noreply.github.com>
We use `rustc-hash::FxHashMap/Set` on src/visibility_tracker.rs this is an implementation detail as AFAIK all types there are `pub(crate)` so we never return an `FxHashMap` or `FxHashSet` on a public interface. This bring a nice perf increase: ```console ❯ cargo criterion --bench indexed_crate IndexedCrate/new(aws-sdk-ec2) time: [1.3474 s 1.3506 s 1.3537 s] change: [+4.4411% +4.8278% +5.2381%] (p = 0.00 < 0.05) Performance has regressed. ❯ cargo criterion --bench indexed_crate --features rustc-hash IndexedCrate/new(aws-sdk-ec2) time: [1.1555 s 1.1561 s 1.1567 s] change: [-14.603% -14.405% -14.192%] (p = 0.00 < 0.05) Performance has improved. ❯ cargo criterion --bench indexed_crate --features rayon IndexedCrate/new(aws-sdk-ec2) time: [577.26 ms 578.45 ms 579.70 ms] change: [-50.083% -49.964% -49.852%] (p = 0.00 < 0.05) Performance has improved. ❯ cargo criterion --bench indexed_crate --features rayon,rustc-hash IndexedCrate/new(aws-sdk-ec2) time: [486.94 ms 488.49 ms 490.13 ms] change: [-15.862% -15.552% -15.212%] (p = 0.00 < 0.05) Performance has improved. ``` Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>
We use `rustc-hash::FxHashMap/Set` on src/visibility_tracker.rs this is an implementation detail as AFAIK all types there are `pub(crate)` so we never return an `FxHashMap` or `FxHashSet` on a public interface. This bring a nice perf increase: ```console ❯ cargo criterion --bench indexed_crate IndexedCrate/new(aws-sdk-ec2) time: [1.3474 s 1.3506 s 1.3537 s] change: [+4.4411% +4.8278% +5.2381%] (p = 0.00 < 0.05) Performance has regressed. ❯ cargo criterion --bench indexed_crate --features rustc-hash IndexedCrate/new(aws-sdk-ec2) time: [1.1555 s 1.1561 s 1.1567 s] change: [-14.603% -14.405% -14.192%] (p = 0.00 < 0.05) Performance has improved. ❯ cargo criterion --bench indexed_crate --features rayon IndexedCrate/new(aws-sdk-ec2) time: [577.26 ms 578.45 ms 579.70 ms] change: [-50.083% -49.964% -49.852%] (p = 0.00 < 0.05) Performance has improved. ❯ cargo criterion --bench indexed_crate --features rayon,rustc-hash IndexedCrate/new(aws-sdk-ec2) time: [486.94 ms 488.49 ms 490.13 ms] change: [-15.862% -15.552% -15.212%] (p = 0.00 < 0.05) Performance has improved. ``` Co-authored-by: Jalil David Salamé Messina <60845989+jalil-salame@users.noreply.github.com>
We use `rustc-hash::FxHashMap/Set` on src/visibility_tracker.rs this is an implementation detail as AFAIK all types there are `pub(crate)` so we never return an `FxHashMap` or `FxHashSet` on a public interface. This bring a nice perf increase: ```console ❯ cargo criterion --bench indexed_crate IndexedCrate/new(aws-sdk-ec2) time: [1.3474 s 1.3506 s 1.3537 s] change: [+4.4411% +4.8278% +5.2381%] (p = 0.00 < 0.05) Performance has regressed. ❯ cargo criterion --bench indexed_crate --features rustc-hash IndexedCrate/new(aws-sdk-ec2) time: [1.1555 s 1.1561 s 1.1567 s] change: [-14.603% -14.405% -14.192%] (p = 0.00 < 0.05) Performance has improved. ❯ cargo criterion --bench indexed_crate --features rayon IndexedCrate/new(aws-sdk-ec2) time: [577.26 ms 578.45 ms 579.70 ms] change: [-50.083% -49.964% -49.852%] (p = 0.00 < 0.05) Performance has improved. ❯ cargo criterion --bench indexed_crate --features rayon,rustc-hash IndexedCrate/new(aws-sdk-ec2) time: [486.94 ms 488.49 ms 490.13 ms] change: [-15.862% -15.552% -15.212%] (p = 0.00 < 0.05) Performance has improved. ``` Co-authored-by: Jalil David Salamé Messina <60845989+jalil-salame@users.noreply.github.com>
We use
rustc-hash::FxHashMap/Set
on src/visibility_tracker.rs this is an implementation detail as AFAIK all types there arepub(crate)
so we never return anFxHashMap
orFxHashSet
on a public interface.This bring a nice perf increase:
I set it as an off by default feature, but seeing as it comes with not public interface changes AFAIK we might want it to be an on by default feature, or just be a direct dependency.
rustc-hash
is a well maintained small crate so I feel good about turning it on by default.