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 fnv instead of SipHasher for HashMaps. add type FnvMap #106

Merged
merged 4 commits into from
Aug 10, 2016

Conversation

leshow
Copy link
Contributor

@leshow leshow commented Aug 9, 2016

@brendanzab mentioned putting the FnvMap alias elsewhere, the map appears to be most used in base/src though. I'm open to any suggestions.

All tests pass.

Fixes #95

pub type TcType = ast::AstType<Symbol>;
pub type TcIdent = ast::TcIdent<Symbol>;

pub type FnvMap<K, V> = HashMap<K, V, BuildHasherDefault<FnvHasher>>;
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we could have a gluon_base::fnv module, with:

extern crate fnv;

...

pub use self::fnv::FnvHasher;

pub type FnvMap<K, V> = HashMap<K, V, BuildHasherDefault<FnvHasher>>;

@leshow
Copy link
Contributor Author

leshow commented Aug 9, 2016

Sure, I'll move it out of types and add to the PR

@brendanzab
Copy link
Member

Just so you understand my reasoning, the name types refers to the fact that these are the data structures used for gloun's typechecking. The naming might be initially confusing though as many Rust libraries use the same name to contain their common data structures.

@leshow
Copy link
Contributor Author

leshow commented Aug 9, 2016

Yep, I follow, I appreciate your guidance, thanks!

I've run the tests again following the refactor, everything seems fine.

use std::fmt;
use std::hash::Hash;
use std::iter::{FromIterator, IntoIterator};
use std::ops::{Index, IndexMut};

use fnv::FnvMap;
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Could you add a space between this and the doc comment?

@brendanzab
Copy link
Member

brendanzab commented Aug 9, 2016

In your PR description, can you add 'Fixes #95' at the top? That will mean that the issue will be auto-closed when we merge.

You also might be interested in joining our gitter channel (if you didn't know about it already) where we have more real-time discussions: https://gitter.im/Marwes/gluon

@Marwes
Copy link
Member

Marwes commented Aug 9, 2016

In your PR description, can you add 'Fixes #95' at the top?

👍 Otherwise it is also possible to add this in the merge commit.

///
/// The default hashing implementation in std::collections uses `SipHasher`
/// since gluon doesn't need the cryptographic quarantee provided by SipHasher,
/// we've opted for the faster fnv hash.
Copy link
Member

Choose a reason for hiding this comment

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

Should be above the struct! ^_^

Copy link
Member

Choose a reason for hiding this comment

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

Woops, I mean 'type alias'

@Marwes
Copy link
Member

Marwes commented Aug 9, 2016

The results vary quite a lot but for typechecking I am seeing a 5-10% speedup. Probably a bit overshadowed by inefficiencies elsewhere but its still a nice speedup!

Before

test clone_prelude     ... bench:     248,752 ns/iter (+/- 142,182)
test typecheck_prelude ... bench:  12,221,382 ns/iter (+/- 3,601,499)
test prelude ... bench:  19,270,757 ns/iter (+/- 1,817,400)

After

test clone_prelude     ... bench:     252,140 ns/iter (+/- 159,846)
test typecheck_prelude ... bench:  11,597,207 ns/iter (+/- 2,093,485)
test prelude ... bench:  18,961,071 ns/iter (+/- 3,236,183)

(clone_prelude measure overhead due to cloning the AST every iteration in typecheck_prelude)

@Marwes
Copy link
Member

Marwes commented Aug 9, 2016

I seem to have caused caused some merge conflicts by merging #102, sorry!

@leshow
Copy link
Contributor Author

leshow commented Aug 9, 2016

Is there anything you still want me to do on this? Do you want me to rebase or merge and resolve the conflicts?

@Marwes
Copy link
Member

Marwes commented Aug 9, 2016

Just rebase and move the comment as @brendanzab wrote and this should be good!

@Marwes Marwes merged commit 4a64c68 into gluon-lang:master Aug 10, 2016
@Marwes
Copy link
Member

Marwes commented Aug 10, 2016

Merged! Thanks!

@brendanzab
Copy link
Member

Thanks again @leshow!

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.

3 participants