gh-109653: Speedup import of threading module#114509
gh-109653: Speedup import of threading module#114509AlexWaygood merged 3 commits intopython:mainfrom
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 <Alex.Waygood@Gmail.com>
AlexWaygood
left a comment
There was a problem hiding this comment.
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 <Alex.Waygood@Gmail.com>
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