bpo-44376 - reduce pow() overhead for small exponents #26662
Merged
+46
−5
Conversation
Reduce pow() overhead for small exponents. Incidentally fixed a refcount oversight for negative exponents.
It's annoying, but I don't want to fight about it ;-)
Wow - that appeared to do the trick! Thank you |
instead of left-to-right. This cuts the time for exponent 2 by another 10%. Does that slow things for, e.g., an exponent like 1 << 20? Sure, by a little. But that exponent will go on to do 20 squarings, and the extra native 32-bit shift- and-tests in the loop are insignificant in comparison. For a tiny exponent (like 2), the loop's shift-and-tests can consume a significant part of the total time. Also reverted the change I made to repair refcounting in modular inverse code. Mark will make the change in a distinct PR, and backport it. Without this change, the "negative refcount" glitch stopped showing up in this PR's code after I changed it to never return `a` directly.
until the exponent is at least 4. Saves approaching another 10% for exponent 2.
insteads works OK, but was always a conceptual mess.
LGTM |
Close to another 10% saved for exponent 2.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
BPO-44376
Reduce pow() overhead for small exponents.
Incidentally fixed a refcount oversight for
negative exponents.
https://bugs.python.org/issue44376