Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Minor Performance Regression Initializing threading.Event #96349

Closed
Labels
performancePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directory
@dgiger42

Description

@dgiger42

Bug report

In the main Python branch, creating athreading.Event is slightly slower than it was in 3.10:

I ran a simple benchmark on the main branch (built with--enable-optimizations):

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

And on 3.10:

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

When initializing anEvent, it creates aCondition viaCondition(Lock()). TheCondition's__init__() then has to catch 3 exceptions in these blocks:

try:self._release_save=lock._release_saveexceptAttributeError:passtry:self._acquire_restore=lock._acquire_restoreexceptAttributeError:passtry:self._is_owned=lock._is_ownedexceptAttributeError:pass

My understanding is that the new zero-cost exceptions maketry/except blocks significantly faster when an exceptionisn't thrown, but don't help when the exception is actually thrown.

ForCondition 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

  • CPython versions tested on: 3.10, 3.12
  • Operating system and architecture: Ubuntu 20.04, x86_64

Metadata

Metadata

Assignees

No one assigned

    Labels

    performancePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directory

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp