Skip to content

Conversation

@ngoldbaum
Copy link
Contributor

This uses thread-local storage to avoid a scaling bottleneck due to a global cache in CPython internals. Unfortunately it's pretty slow ~10% of the total runtime of my benchmark is in the type_lookup function, I'm going to look at whether it can be faster...

Also refactors some rust code so it doesn't block other threads from doing work if the interpreter requests a GC pass.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 10, 2025
@nascheme
Copy link

I created a bug in the cpython issue tracker: python/cpython#132380

Based on my benchmark runs, my proposed PR for 3.13 removes the need for type_lookup() function.

@nascheme
Copy link

I implemented an alternative fix for CPython, which we can also backport to Python 3.13. It adds a specialized and faster type lookup function if using a non-interned name:

python/cpython#132652

@ngoldbaum
Copy link
Contributor Author

FWIW the latest upstream patch for this is python/cpython#133669. I think @nascheme is still planning to have a fix merged before 3.14rc1.

@zsol
Copy link
Contributor

zsol commented May 22, 2025

How much of this pr do you think is still useful after that patch lands in cpython?

@ngoldbaum
Copy link
Contributor Author

The avoiding holding the GIL in the native library helps a little.

I haven't actually been able to find a way to beat multiprocessing using libcst. There's still some contention due to GC pauses.

@zsol zsol changed the title WIP: fix contention on free-threaded build Reduce contention on free-threaded build May 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants