Skip to content

WIP: fix contention on free-threaded build #1325

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

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.

zsol and others added 9 commits April 9, 2025 15:32
Instead of relying on `multiprocessing.Pool`, this PR replaces the implementation of `parallel_exec_transform_with_prettyprint` with `concurrent.futures.ProcessPoolExecutor`
This PR:
1. marks the `libcst.native` module as free-threading-compatible
2. replaces the use of ProcessPoolExecutor with ThreadPoolExecutor if free-threaded CPython is detected at runtime

This depends on Instagram#1294 and Instagram#1289.
Co-authored-by: Nathan Goldbaum <[email protected]>
@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

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