Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
gh-109653: Speedup import of threading module#114509
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
gh-109653: Speedup import of threading module #114509
Uh oh!
There was an error while loading. Please reload this page.
Conversation
danielhollas commented Jan 23, 2024 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Delayed import of functools leads to 50% speedup of import time.
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
danielhollas commented Jan 24, 2024 • edited by hugovk
Loading Uh oh!
There was an error while loading. Please reload this page.
edited by hugovk
Uh oh!
There was an error while loading. Please reload this page.
To be precise, compiling python with |
ajoino commented Jan 24, 2024
Just a thought, is it even necessary to use |
AlexWaygood commented Jan 24, 2024
This was my thought as well on first seeing the patch. |
danielhollas commented Jan 24, 2024
Looking at the code, the |
AlexWaygood commented Jan 24, 2024
Oh, great point 😄 In that case, let's just go with a |
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Alex Waygood <[email protected]>
AlexWaygood left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks! I'd love to check with a core dev more familiar with subinterpreters before merging, though (since this feature was specifically added to help with subinterpreter support).
@ericsnowcurrently, there's no reason why switching to a lambda rather than functools.partial could be problematic for subinterpreter support, is there?
danielhollas commented Jan 24, 2024
@AlexWaygood thanks!
Just a note, if this was a problem, we could still get away with it by simply not doing either: the function is (at least currently) being called without any extra |
threading moduleAlexWaygood commented Jan 31, 2024
I can't see a way in which this would cause problems — I'll go ahead and merge, since it's been a few days :) Thanks @danielhollas! |
ericsnowcurrently commented Feb 1, 2024
I'm not aware of any such reason. |
Uh oh!
There was an error while loading. Please reload this page.
Avoiding an import of functools leads to 50% speedup of import time. Co-authored-by: Alex Waygood <[email protected]>
Delayed import of
functoolsspeeds up theimport threadingby ~50% (2ms -> 1ms) in my testing.Since the
functoolsmodule is only used in the internal_register_atexitfunction that is called byconcurrent.futures, this seems like a worthwhile win for users ofthreadingmodule who do not useasyncio.Part of #109653
CC @AlexWaygood