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

Avoid intermediate Vec allocations #295

Merged
merged 2 commits into from
Oct 28, 2023

Conversation

Swatinem
Copy link
Contributor

This is on top of #294, but I can also rebase if needed


Previously, each try_generate_hash call would allocate a bunch of new Vecs just
to throw them away every time.

Now, all these Vecs are kept around in a stateful Generator struct and reused across
multiple try_generate_hash calls.

As generation of the PHF is probabilistic, it may need lots of trials, and reusing allocations
across multiple trials may be benefitial.

Swatinem added 2 commits July 30, 2023 12:21
Solves part of rust-phf#88 by providing a separate function to customize the hashing function during generation.
That way, one can avoid usage of the default SipHash as well as avoid having a `PhfHash` bound on the keys.
This custom hash function can be used in combination with `get_index` directly.
Previously, each `try_generate_hash` call would allocate a bunch of new `Vec`s just
to throw them away every time.

Now, all these `Vec`s are kept around in a stateful `Generator` struct and reused across
multiple `try_generate_hash` calls.

As generation of the PHF is probabilistic, it may need lots of trials, and reusing allocations
across multiple trials may be benefitial.
Copy link
Member

@JohnTitor JohnTitor left a comment

Choose a reason for hiding this comment

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

Great, let's try this as a major change. Thanks!

@JohnTitor JohnTitor added this pull request to the merge queue Oct 28, 2023
Merged via the queue into rust-phf:master with commit ac49464 Oct 28, 2023
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.

2 participants