Opened 7 years ago
Closed 7 years ago
#29065 closed Cleanup/optimization (fixed)
Make django.core.validators only load Pillow if needed
Reported by: | Collin Anderson | Owned by: | nobody |
---|---|---|---|
Component: | Core (Other) | Version: | 2.0 |
Severity: | Normal | Keywords: | |
Cc: | Collin Anderson, Akshesh Doshi | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Before #21548, Pillow was only loaded if needed. It would be nice if this were still true.
Change History (8)
comment:1 by , 7 years ago
Cc: | added |
---|---|
Has patch: | set |
Summary: | Don't load Pillow unless needed → Only load Pillow if needed |
comment:2 by , 7 years ago
Component: | File uploads/storage → Core (Other) |
---|---|
Type: | Uncategorized → Cleanup/optimization |
Can you elaborate on the motivation for this?
comment:3 by , 7 years ago
Cc: | added |
---|
comment:4 by , 7 years ago
A few advantages:
If for some reason you can't or have trouble installing pillow, everything else will work fine. It makes django a bit more "lightweight" to have the dependency be optional.
Loading Pillow increases memory usage by 5% (2mb) (in my quick testing) for a runserver on an empty project:
37608kb without loading pillow
39768kb with loading pillow
Also, doesn't matter quite as much, but running "check" also takes about 5% longer (25ms) on an empty project for me when including pillow:
360-400ms without loading pillow
393-424ms with loading pillow
I should also note that pretty much every other spot in the codebase tries to make the Pillow dependency optional by not making the import at the top of the file.
comment:6 by , 7 years ago
Summary: | Only load Pillow if needed → Make django.core.validators only load Pillow if needed |
---|
Isn't it already "optional" with the try/except ImportError
? I think the idea you're proposing is to import it lazily (which could help if it's installed but unused) which makes sense to me.
https://github.com/django/django/pull/9619