My understanding is that the new zero-cost exceptions make try/except blocks significantly faster when an exception isn't thrown, but don't help when the exception is actually thrown.
For Condition objects, I think it would likely be easy to avoid this minor slowdown by using hasattr() instead of the try/except blocks, and it would also be more concise.
Your environment
CPython versions tested on: 3.10, 3.12
Operating system and architecture: Ubuntu 20.04, x86_64
The text was updated successfully, but these errors were encountered:
Bug report
In the main Python branch, creating a
threading.Event
is slightly slower than it was in 3.10:I ran a simple benchmark on the main branch (built with
--enable-optimizations
):And on 3.10:
When initializing an
Event
, it creates aCondition
viaCondition(Lock())
. TheCondition
's__init__()
then has to catch 3 exceptions in these blocks:My understanding is that the new zero-cost exceptions make
try
/except
blocks significantly faster when an exception isn't thrown, but don't help when the exception is actually thrown.For
Condition
objects, I think it would likely be easy to avoid this minor slowdown by usinghasattr()
instead of thetry
/except
blocks, and it would also be more concise.Your environment
The text was updated successfully, but these errors were encountered: