Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.3k
gh-100762: Switch order of exception match in gen_close#101011
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
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.
Seems good. Let's wait for 3.13 in two weeks, since performance improvements are effectively frozen right now.
@brandtbucher Thanks for looking into this. The main branch has changed in the meantime, and there is currently only a single match instead of the two before. This makes this PR irrelevant, I will close it. |
Uh oh!
There was an error while loading.Please reload this page.
This PR optimizes the closing of generators by switching the match statements in the expression
PyErr_ExceptionMatches(PyExc_StopIteration) || PyErr_ExceptionMatches(PyExc_GeneratorExit)from thegen_closemethod. The case of aPyExc_GeneratorExitis more common.Benchmark (with optimizations including PGO)updated May 9th:
Benchmark script:
Notes:
PyExc_StopIterationis triggered occur less than thePyExc_GeneratorExit. Cases from the python test suite aretest_async_gen_asyncio_aclose_10intest_asyncgen.pyand the following code fromtest_generators.py: