Skip to content

Jpeg load performance regression for Pillow 5.1+ from wheels #3441

@kkopachev

Description

@kkopachev

What did you do?

Performance regression when opening (and loading) a jpeg file in Pillow, installed from wheels on x86_64 linux. Affects loading of jpeg files. Regression happened updating from Pillow 5.0.0 to 5.1.0 (up to 5.3.0)

What are your OS, Python and Pillow versions?

  • OS: linux, x86_64
  • Python: 2.7, 3.7
  • Pillow: 5.1.0+

I am not sure where this issue belongs to, seems to be related to wheels building somehow.

Original issue was created in thumbor repo thumbor/thumbor#1102 saying there was a noticeable performance regression. Upon further investigation, I was able to come up with simple reproduction steps.

docker run --rm -it python:2 bash
root@9e6e1f13f44a:/# wget -q wget https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg
root@9e6e1f13f44a:/# pip install pillow==5.0.0
Collecting pillow==5.0.0
  Downloading https://files.pythonhosted.org/packages/89/bd/1d9a10f3e8157b7df275740b0782a892a0db387f8286620110c41e5146c7/Pillow-5.0.0-cp27-cp27mu-manylinux1_x86_64.whl (5.8MB)
    100% |████████████████████████████████| 5.9MB 1.5MB/s 
Installing collected packages: pillow
Successfully installed pillow-5.0.0
You are using pip version 18.0, however version 18.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
root@9e6e1f13f44a:/# wget https://upload.wikimedia.org/wikipedia/commons/b/b4/JPEG_example_JPG_RIP_100.jpg
root@9e6e1f13f44a:/#
root@9e6e1f13f44a:/#
root@9e6e1f13f44a:/# python -m timeit -n1000 -r5 -s'from PIL import Image' 'Image.open("JPEG_example_JPG_RIP_100.jpg").load()'
1000 loops, best of 5: 2.58 msec per loop
root@9e6e1f13f44a:/#
root@9e6e1f13f44a:/#
root@9e6e1f13f44a:/# pip install pillow==5.1.0
Collecting pillow==5.1.0
  Using cached https://files.pythonhosted.org/packages/00/49/a0483e7308b4b04b5a898789911dbb876d9fea54e7df0453915e47744cfd/Pillow-5.1.0-cp27-cp27mu-manylinux1_x86_64.whl
Installing collected packages: pillow
  Found existing installation: Pillow 5.0.0
    Uninstalling Pillow-5.0.0:
      Successfully uninstalled Pillow-5.0.0
Successfully installed pillow-5.1.0
You are using pip version 18.0, however version 18.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
root@9e6e1f13f44a:/#
root@9e6e1f13f44a:/#
root@9e6e1f13f44a:/# python -m timeit -n1000 -r5 -s'from PIL import Image' 'Image.open("JPEG_example_JPG_RIP_100.jpg").load()'
1000 loops, best of 5: 5.77 msec per loop
root@9e6e1f13f44a:/#

In short - Pillow 5.1.0 takes 5.77 msec to open test JPEG file. However Pillow 5.0.0 took 2.58 msec to open the same file.

I did try to build both Pillow versions from source (only enabling libjpeg) and in that case they show same performance.
I thought maybe for Pillow 5.1 you switched to libjpeg9c, so I built both Pillow versions with libjpeg9c - no performance difference.

As people report in original thumbor ticket, they are not able to repro it on OSX, so I assume it's linux only.

As a last resort, I copied libjpeg.so from what was shipped with wheels for Pillow 5.0.0 and copied it over to Pillow 5.1 installed from wheels - no performance difference.

I suspect something wrong with how libjpeg got build starting from Pillow 5.1.0. I tried 5.2.0 and 5.3.0 - both experience same issue.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions