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

Hash up to 8 bytes at once with FxHasher #1

Merged
merged 3 commits into from
May 28, 2018
Merged

Conversation

Zoxc
Copy link
Contributor

@Zoxc Zoxc commented May 27, 2018

@kennytm
Copy link
Member

kennytm commented May 27, 2018

r? @michaelwoerister

bytes = &bytes[2..];
}
if (size_of::<usize>() > 1) && bytes.len() >= 1 {
hash.add_to_hash(bytes[0] as usize);
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't all of this mean that splitting a write call changes the hash? IIRC it shouldn't.
Could an union { bytes: [u8; size_of::<usize>()], usize: usize } buffer be used instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That doesn't seem to be a documented nor a useful property.

Copy link
Member

Choose a reason for hiding this comment

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

cc @michaelwoerister @gankro I remember discussions about this property

Note that it's potentially useful to buffer the values if, with e.g. nested enums, you're writing byte-sized values (i.e. discriminants) most of the time, one at a time.

Copy link
Member

Choose a reason for hiding this comment

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

Since the FxHasher is only used with hash tables, I don't think that the hash must be stable. As long as it is deterministic for our use cases, it's fine, I think. It already treats (u8, u8) different from u16 where a similar argument could be made.

My view is: FxHasher should be the absolute fastest for small keys and it should do whatever it can get away with in practice.

Copy link
Member

@eddyb eddyb May 27, 2018

Choose a reason for hiding this comment

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

I still think we should try and bench this against some buffering scheme, especially if it can all be inlined down to a few applications of the usize "block" function.

EDIT: nevermind, all the leaves I was thinking off go through the write_uN methods below, so those would also need to be buffered somehow to observe a benefit.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, we don't need to do this in this PR. The benchmarks showed that it's an improvement.

As a sidenote, using perf.rlo is a lot more complicated when testing out-of-tree crates...

@michaelwoerister
Copy link
Member

The only problem I see here does not have to do with the PR directly: Since this is a standalone crate now, it should have tests and integrate with travis. Seeing that all tests pass makes approving a PR much simpler.

Cargo.lock Outdated
[[package]]
name = "rustc-hash"
version = "0.1.0"
Copy link
Member

Choose a reason for hiding this comment

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

Why does a library crate have a Cargo.lock?

@michaelwoerister
Copy link
Member

I think the version number needs to be bumped so we can publish on crates.io.

@michaelwoerister
Copy link
Member

I'll merge this because it was already tested as part of rustc_data_structures. The next PR will have to add tests and CI integration though.

@michaelwoerister michaelwoerister merged commit 1e61258 into master May 28, 2018
@Zoxc Zoxc deleted the batch-bytes branch May 28, 2018 18:42
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