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.

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