-
-
Notifications
You must be signed in to change notification settings - Fork 33k
bpo-46407: Optimizing power-of-2 operations #30628
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
bpo-46407: Optimizing power-of-2 operations #30628
Conversation
Misc/NEWS.d/next/Core and Builtins/2022-01-17-07-34-16.bpo-46407.00aN9w.rst
Outdated
Show resolved
Hide resolved
Come to think of it, this is kind of two separate orthogonal changes, right? It may be easier to benchmark, review and get parts merged if this was two PRS, one to implement the |
…07.00aN9w.rst Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
How should I separate it? Should I get rid of the |
Sounds good to me |
Use the DIGIT_ONE static variable whenever possible
Misc/NEWS.d/next/Core and Builtins/2022-01-17-07-34-16.bpo-46407.00aN9w.rst
Outdated
Show resolved
Hide resolved
…07.00aN9w.rst Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
It seems like this PR has lost all activity. |
I'm unassigning myself from review. I think @tim-one would be better placed to decide whether this is an optimisation worth making, and if so review the code. |
PR bump. |
PR bump 2. |
PR bump 3. |
PR has lost all activity. |
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.
I appreciate the effort, but I'm inclined to reject this change. The increase in code complexity isn't justified by the relatively small (~6%) speedup the bpo report showed for a best-case isolated microbenchmark (x**10000000
after x=2
). There are few cases the patch can help with, but testing for those cases slightly slows down all other cases (tests-and-branches to skip the new code), and also blows space in I cache for code that won't be executed most times.
long_pow()
in particular is already a long-winded function without this, where existing optimizations have major payoffs that apply in many cases. The generality and high bang-for-the-buck nature of those justify their code complexity.
The other change - introducing remainder-only functions - was much more attractive on these grounds (no runtime tests needed - we pick which we want in each context at compile-time, and they're always faster when they're picked).
I see. |
https://bugs.python.org/issue46407