Visitar URL original
gh-140795: fetch thread state once on fast path for critical sections by kumaraditya303 · Pull Request #141406 · python/cpython · GitHub
The Wayback Machine - https://web.archive.org/web/20251112062808/https://github.com/python/cpython/pull/141406
Skip to content

Conversation

@kumaraditya303
Copy link
Contributor

@kumaraditya303 kumaraditya303 commented Nov 11, 2025 •

Currently on the fastpath for critical section where the objects are not locked, the thread state is fetched twice once while acquiring it and once while releasing it. This PR optimizes it to fetch it once and store it (in a temp variable on stack) so that on the fastpath thread state is fetched once.
This should help performance in shared modules such as ssl where thread state access is slower because of extra function call to _PyThreadState_GetCurrent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant