-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
gh-109653: Speedup import of threading module #114509
Conversation
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 |
To be precise, compiling python with |
Just a thought, is it even necessary to use |
This was my thought as well on first seeing the patch. |
Looking at the code, the |
Oh, great point 😄 In that case, let's just go with a |
Co-authored-by: Alex Waygood <[email protected]>
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?
@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
module
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! |
I'm not aware of any such reason. |
Avoiding an import of functools leads to 50% speedup of import time. Co-authored-by: Alex Waygood <[email protected]>
Delayed import of
functools
speeds up theimport threading
by ~50% (2ms -> 1ms) in my testing.Since the
functools
module is only used in the internal_register_atexit
function that is called byconcurrent.futures
, this seems like a worthwhile win for users ofthreading
module who do not useasyncio
.Part of #109653
CC @AlexWaygood