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

rustc: Move to FNV hashing for node/def ids #12635

Merged
merged 2 commits into from
Mar 7, 2014

Conversation

alexcrichton
Copy link
Member

This leverages the new hashing framework and hashmap implementation to provide a
much speedier hashing algorithm for node ids and def ids. The hash algorithm
used is currentl FNV hashing, but it's quite easy to swap out.

I originally implemented hashing as the identity function, but this actually
ended up in slowing down rustc compiling libstd from 8s to 13s. I would suspect
that this is a result of a large number of collisions.

With FNV hashing, we get these timings (compiling with --no-trans, in seconds):

before after
libstd 8.324 6.703
stdtest 47.674 46.857
libsyntax 9.918 8.400

@erickt
Copy link
Contributor

erickt commented Mar 1, 2014

This is great. I'm thrilled the new hash framework is already proving useful.

@alexcrichton
Copy link
Member Author

I embarassingly never built this past a stage1 rustc, so this ended up not compiling at all on the bots. The reason for this is that deriving(Hash) expansion did not use type parameters after stage0 (it was changed recently).

I added a commit to modify how deriving(Hash) expands if default type parameters are enabled for the local crate. re-r?

pub mod NodeMap {
use collections::HashMap;
pub fn new<T>() -> super::NodeMap<T> {
HashMap::with_hasher(super::FnvHasher)
Copy link
Member

Choose a reason for hiding this comment

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

Why isn't HashMap::new implemented for all Hasher types that implement Default?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sadly that can't be done because it would resolve in ambiguities:

let mut map = HashMap::new();
map.insert(1u, 2u);

What type does the hasher have?

@thestinger
Copy link
Contributor

The SipHash implementation is far from ideal, so perhaps it should just be improved instead. It hashes at a fraction of the speed of the highly optimized sample implementations.

@brson
Copy link
Contributor

brson commented Mar 6, 2014

r=me, but the conditional deriving thing strikes me as a bug that i hope goes away.

This leverages the new hashing framework and hashmap implementation to provide a
much speedier hashing algorithm for node ids and def ids. The hash algorithm
used is currentl FNV hashing, but it's quite easy to swap out.

I originally implemented hashing as the identity function, but this actually
ended up in slowing down rustc compiling libstd from 8s to 13s. I would suspect
that this is a result of a large number of collisions.

With FNV hashing, we get these timings (compiling with --no-trans, in seconds):

|           |  before  |  after  |
|-----------|---------:|--------:|
| libstd    |   8.324  |  6.703  |
| stdtest   |  47.674  | 46.857  |
| libsyntax |   9.918  |  8.400  |
If #[feature(default_type_parameters)] is enabled for a crate, then
deriving(Hash) will expand with Hash<W: Writer> instead of Hash<SipState> so
more hash algorithms can be used.
bors added a commit that referenced this pull request Mar 7, 2014
This leverages the new hashing framework and hashmap implementation to provide a
much speedier hashing algorithm for node ids and def ids. The hash algorithm
used is currentl FNV hashing, but it's quite easy to swap out.

I originally implemented hashing as the identity function, but this actually
ended up in slowing down rustc compiling libstd from 8s to 13s. I would suspect
that this is a result of a large number of collisions.

With FNV hashing, we get these timings (compiling with --no-trans, in seconds):

|           |  before  |  after  |
|-----------|---------:|--------:|
| libstd    |   8.324  |  6.703  |
| stdtest   |  47.674  | 46.857  |
| libsyntax |   9.918  |  8.400  |
@bors bors closed this Mar 7, 2014
@bors bors merged commit 0a84132 into rust-lang:master Mar 7, 2014
@alexcrichton alexcrichton deleted the speedy-hash branch March 7, 2014 06:57
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 25, 2022
Correct target_feature completion

I changed the `target_feature` to match the description given in rust-lang#12616.
flip1995 pushed a commit to flip1995/rust that referenced this pull request Apr 18, 2024
Use `check_attributes` in doc lints

Ensures we catch all the places that doc comments could occur, found one that we were currently missing - docs on `extern` items

changelog: none
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.

6 participants