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.

@colesbury
Copy link
Contributor

How much of a difference does this make to asyncio_tcp_ssl?

@kumaraditya303
Copy link
Contributor Author

How much of a difference does this make to asyncio_tcp_ssl?

It is ~5% faster on macOS with this change.

@kumaraditya303 kumaraditya303 merged commit 49ff8b6 into python:main Nov 21, 2025
50 checks passed
@kumaraditya303 kumaraditya303 deleted the critical-section branch November 21, 2025 14:19
StanFromIreland pushed a commit to StanFromIreland/cpython that referenced this pull request Dec 6, 2025
ashm-dev pushed a commit to ashm-dev/cpython that referenced this pull request Dec 8, 2025
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.

2 participants