Skip to content

bpo-42161: mathmodule.c: move _PyLong_GetOne() loop invariant #26391

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

Merged
merged 1 commit into from
May 26, 2021
Merged

bpo-42161: mathmodule.c: move _PyLong_GetOne() loop invariant #26391

merged 1 commit into from
May 26, 2021

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented May 26, 2021

Move _PyLong_GetZero() and _PyLong_GetOne() loop invariants outside
loops in functions:

  • math.comb()
  • math.gcd()
  • math.lcm()
  • math.perm()

https://bugs.python.org/issue42161

Move _PyLong_GetZero() and _PyLong_GetOne() loop invariants outside
loops in functions:

* math.comb()
* math.gcd()
* math.lcm()
* math.perm()
@vstinner
Copy link
Member Author

This change should be backport to 3.10 since it fix a minor performance regression introduced in Python 3.10: https://bugs.python.org/issue42161#msg388988

@vstinner
Copy link
Member Author

cc @rhettinger

@vstinner
Copy link
Member Author

I didn't notice that _PyLong_GetZero() and _PyLong_GetOne() were used in loops in Modules/mathmodule.c when I wrote my commit 3783413 (I tried to pay attention to that, to avoid performance regression).

@vstinner vstinner merged commit 3e7ee02 into python:main May 26, 2021
@miss-islington
Copy link
Contributor

Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.10.
🐍🍒⛏🤖

@vstinner vstinner deleted the math_micro_optim branch May 26, 2021 22:51
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 26, 2021
…GH-26391)

Move _PyLong_GetZero() and _PyLong_GetOne() loop invariants outside
loops in functions:

* math.comb()
* math.gcd()
* math.lcm()
* math.perm()
(cherry picked from commit 3e7ee02)

Co-authored-by: Victor Stinner <vstinner@python.org>
@bedevere-bot
Copy link

GH-26393 is a backport of this pull request to the 3.10 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.10 only security fixes label May 26, 2021
@vstinner
Copy link
Member Author

Thanks for the review @erlend-aasland.

vstinner added a commit that referenced this pull request May 26, 2021
…) (GH-26393)

Move _PyLong_GetZero() and _PyLong_GetOne() loop invariants outside
loops in functions:

* math.comb()
* math.gcd()
* math.lcm()
* math.perm()
(cherry picked from commit 3e7ee02)

Co-authored-by: Victor Stinner <vstinner@python.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants