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

Make a faster HASH_ITER macro and make other hash optimizations #901

Merged
merged 1 commit into from Jul 9, 2018

Conversation

samcv
Copy link
Member

@samcv samcv commented Jul 8, 2018

HASH_ITER_FAST is faster and it doesn't randomize bucket order (though
it's faster regardless of that).

Makes the biggest difference when we are iterating a hash with a LOT of
keys in it, such as adding a million keys to a hash then deleting and
adding back again. Got about 40% speed improvement on this nqp script:
https://gist.github.com/9a65a586ea21b20def8efe4aaaab55de

Also optimize GET_X_BITS by making a switch out of it. It doesn't seem
like this would be faster, but it is due to compiler optimizations.

#define HASH_CNT(hh,head) ((head)?((head)->hh.tbl->num_items):0)

MVM_STATIC_INLINE unsigned GET_X_BITS_FUNCT(MVMuint64 bucket_rand, unsigned log2_num_buckets) {
switch (log2_num_buckets) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Also optimize GET_X_BITS by making a switch out of it. It doesn't seem
like this would be faster, but it is due to compiler optimizations.

Maybe it needs a comment here saying that it is done this way because it's faster? Otherwise someone may refactor it months later :)

@samcv samcv force-pushed the iterspeed branch 6 times, most recently from df7b2a9 to e1f7394 Compare July 9, 2018 10:45
HASH_ITER_FAST is faster and it doesn't randomize bucket order (though
it's faster regardless of that).

Makes the biggest difference when we are iterating a hash with a LOT of
keys in it, such as adding a million keys to a hash then deleting and
adding back again. Got about 40% speed improvement on this nqp script:
https://gist.github.com/9a65a586ea21b20def8efe4aaaab55de
Most of the time spent in the above script was in MVMHash_gc_mark, and
that now uses the fast iterator internally which results in the speed
improvement.

Also optimize GET_X_BITS by making a switch out of it. It doesn't seem
like this would be faster, but it is due to compiler optimizations.
@samcv samcv merged commit a2ca33b into MoarVM:master Jul 9, 2018
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.

None yet

2 participants