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 Collin Anderson, 7 years ago

Cc: Collin Anderson added
Has patch: set
Summary: Don't load Pillow unless neededOnly load Pillow if needed

comment:2 by Tim Graham, 7 years ago

Component: File uploads/storageCore (Other)
Type: UncategorizedCleanup/optimization

Can you elaborate on the motivation for this?

Last edited 7 years ago by Tim Graham (previous) (diff)

comment:3 by Akshesh Doshi, 7 years ago

Cc: Akshesh Doshi added

comment:4 by Collin Anderson, 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.

Last edited 7 years ago by Collin Anderson (previous) (diff)

comment:5 by Loic Bistuer, 7 years ago

Triage Stage: UnreviewedAccepted

+1 to making Pillow truly optional.

comment:6 by Tim Graham, 7 years ago

Summary: Only load Pillow if neededMake 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.

comment:7 by Collin Anderson, 7 years ago

Good point. The installed but unused case is what I'm running into.

comment:8 by Tim Graham <timograham@…>, 7 years ago

Resolution: fixed
Status: newclosed

In 46b3e3f:

Fixed #29065 -- Made django.core.validators only load Pillow if needed.

Note: See TracTickets for help on using tickets.
Back to Top