-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
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
Optimize set.pop() to advance a pointer instead of indexing. #10429
Conversation
FWIW, here is disassembly of the inner-loop which is now very tight:
The set_pop() function entry and exit code is also tighter (formerly it saved and restored three registers, and now it skips that work). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please provide microbenchmarks?
In most cases the loop ends after 1 or 2 iterations. Additional operations before and after the loop can eat the benefit of the optimization of short loop.
Objects/setobject.c
Outdated
} | ||
key = entry->key; | ||
entry->key = dummy; | ||
entry->hash = -1; | ||
so->used--; | ||
so->finger = i + 1; /* next place to start */ | ||
so->finger = entry - so->table; /* next place to start */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is + 1
missed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Thanks for noticing.
I can't run new benchmarks right now (my build has been broken for a couple of days since the extensive include file changes went in). The benchmark looked like this:
|
@rhettinger: Status check is done, and it's a success ✅ . |
Gives approx 20% speed-up using clang depending on the number of elements in the set (the less dense the set, the more the speed-up).
Uses the same entry++ logic used elsewhere in the setobject.c code.