gh-114203: Optimise simple recursive critical sections by Yhg1s · Pull Request #128126 · python/cpython · GitHub
Skip to content

gh-114203: Optimise simple recursive critical sections - #128126

Merged
Yhg1s merged 3 commits into
python:mainfrom
Yhg1s:optimise-recursive-critical-section
Dec 23, 2024
Merged

Yhg1s merged 3 commits into
python:mainfrom
Yhg1s:optimise-recursive-critical-section

Conversation

@Yhg1s

@Yhg1s Yhg1s commented Dec 20, 2024

Copy link
Copy Markdown
Member

Add a fast path to (single-mutex) critical section locking iff the mutex is already held by the top-most critical section of this thread. This can matter a lot for indirectly recursive critical sections without intervening critical sections.

…mutex

is already held by the currently active, top-most critical section of this
thread. This can matter a lot for indirectly recursive critical sections
without intervening critical sections.
Comment thread Include/internal/pycore_critical_section.h
Comment thread Include/internal/pycore_critical_section.h Outdated
should be relatively rare and we don't want to burden the fastest path.
@Yhg1s
Yhg1s marked this pull request as ready for review December 20, 2024 23:03

@gpshead gpshead left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I do wonder if there might be additional optimization opportunities along these lines, but that should be future work if ever needed.

@colesbury colesbury left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@Yhg1s

Yhg1s commented Dec 23, 2024

Copy link
Copy Markdown
Member Author

@Yhg1s

Yhg1s commented Dec 23, 2024

Copy link
Copy Markdown
Member Author

@Yhg1s
Yhg1s merged commit 180d417 into python:main Dec 23, 2024
@Yhg1s
Yhg1s deleted the optimise-recursive-critical-section branch December 23, 2024 12:55
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this pull request Jan 8, 2025
…128126)

Add a fast path to (single-mutex) critical section locking _iff_ the mutex
is already held by the currently active, top-most critical section of this
thread. This can matter a lot for indirectly recursive critical sections
without intervening critical sections.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants