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

perf: faster HashMap with TypeId keys #259

Closed
wants to merge 1 commit into from

Conversation

Purpzie
Copy link

@Purpzie Purpzie commented Aug 27, 2022

TypeIds are already hashes from the compiler, so they don't need to be hashed again. I've added a dummy hasher which just passes the TypeId through without modifying it.

For example, the tracing-subscriber crate does the same thing: https://github.com/tokio-rs/tracing/blob/3517552c319a22c108d423ca9a1675e632f616a3/tracing-subscriber/src/registry/extensions.rs#L12-L34

@SoniEx2
Copy link

SoniEx2 commented Aug 27, 2022

relevant: rust-lang/rust#10389

@Purpzie
Copy link
Author

Purpzie commented Aug 28, 2022

@SoniEx2 There doesn't seem to be a way to avoid that in the first place, since it's a problem in the compiler itself.

@SoniEx2
Copy link

SoniEx2 commented Aug 28, 2022

the point is "stop relying on current implementation details".

like sure, use a faster hasher. but don't break if TypeId changes.

(not panicking/doing nothing in write would be a good start, but would leave hashes as 0. it'd still work if TypeId changed at least, even if a lot slower due to hash collisions. alternatively having a slow path write and a fast path write_u64 would work.)

@jugglerchris
Copy link
Collaborator

Hi @Purpzie ,
Thanks for the contribution!
I'm certainly open to performance improvements if they're correct and significant enough to offset any extra complexity.
Have you measured the difference in performance (i.e. is hashing typeids a significant overhead)?

@khvzak khvzak closed this Feb 6, 2024
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.

4 participants