Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Delayed import of functools leads to 50% speedupof import time.
Most changes to Pythonrequire a NEWS entry. Add one using theblurb_it web app or theblurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
danielhollas commentedJan 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 commentedJan 24, 2024
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 |
Uh oh!
There was an error while loading.Please reload this page.
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
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 wasspecifically added to help with subinterpreter support).
@ericsnowcurrently, there's no reason why switching to alambda
rather thanfunctools.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
moduleI 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. |
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 <Alex.Waygood@Gmail.com>
Uh oh!
There was an error while loading.Please reload this page.
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