Skip to content
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

gh-96349: Fix minor performance regression initializing threading.Event #96350

Merged
merged 1 commit into from
Aug 30, 2022

Conversation

dgiger42
Copy link
Contributor

@dgiger42 dgiger42 commented Aug 28, 2022

There was a minor performance regression making it slightly slower to initialize a threading.Event on the main branch than it was in 3.10. I think the slowdown may have been related to zero-cost exceptions.

This PR removes the slowdown (and makes it faster than it was before).

Here's a simple benchmark with pyperf:

3.10:

../cpython3.10/python -m pyperf timeit -s 'from threading import Event' 'e = Event()'
.....................
Mean +- std dev: 1.52 us +- 0.02 us

Main branch:

../cpython/python -m pyperf timeit -s 'from threading import Event' 'e = Event()'
.....................
Mean +- std dev: 1.59 us +- 0.02 us

With this PR:

../cpython/python -m pyperf timeit -s 'from threading import Event' 'e = Event()'
.....................
Mean +- std dev: 462 ns +- 10 ns

Copy link
Member

@corona10 corona10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, no reason not to merge

Mean +- std dev: [base] 1.53 us +- 0.01 us -> [pr] 493 ns +- 11 ns: 3.11x faster

@corona10 corona10 merged commit 22ed523 into python:main Aug 30, 2022
@dgiger42 dgiger42 deleted the eliminate_minor_perf_regression branch August 30, 2022 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants