Defer imports to improve startup speed#608
Open
hugovk wants to merge 1 commit intojazzband:masterfrom
Open
Conversation
Contributor
|
I think this makes sense when you are loading known slow external packages. But as far as the standard lib is concerned, I'm seeing this as some "overoptimization". So not very fond of this patch, sorry. |
Member
Author
|
Small improvements multiplied by millions of users and computers could definitely help avoid some of the compute power concerns in #607, but okay! |
Contributor
|
I was waiting for such an answer 🤣 You make a point! Until now, I learned from Python best practices that "embedded" imports were mostly reserved to cases where there was circular imports. If you have some articles about that "conflict" between best practices and optimizations (I guess it's some sort of balance to do), I'm interested. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
It can be useful to defer imports so that when people import tablib but don't use certain features (for example, if they don't use JSON format) they can avoid the import cost.
This particularly helps people writing tools like CLIs where startup cost can be a problem.
If people are using tablib and other libraries, the total import times can all add up.
We've been doing this also in the stdlib, for example:
Running:
Before: 8 ms
After: 2 ms