Skip to content

JPEG encoding with Pillow PyPI wheel is 6x slower than distro package #5073

@wangqr

Description

@wangqr

What did you do?

Run the attached script to encode a RGB image to JPEG

What did you expect to happen?

The encoding should take about 1ms

What actually happened?

The encoding takes about 1ms with distribution provided package, but ~6ms with Pillow-8.0.1-cp3*-cp3*-manylinux1_x86_64.whl from PyPI

What are your OS, Python and Pillow versions?

I have tested on ArchLinux, Ubuntu and CentOS. Here are the results (all from same computer):

  • Archlinux
# python-pillow
Python 3.8.6 (default, Sep 30 2020, 04:00:38)
[GCC 10.2.0]
Pillow 7.2.0
0.8895997999999963 ms/iter

# python-pillow-git (619a7b9f)
Python 3.8.6 (default, Sep 30 2020, 04:00:38)
[GCC 10.2.0]
Pillow 8.1.0.dev0
0.8732269799998903 ms/iter

# Pillow from PyPI
Python 3.8.6 (default, Sep 30 2020, 04:00:38)
[GCC 10.2.0]
Pillow 8.0.1
5.752080059999571 ms/iter
  • Ubuntu
# python3-pillow
Python 3.8.5 (default, Jul 28 2020, 12:59:40)
[GCC 9.3.0]
Pillow 7.0.0
1.8287872446002438 ms/iter

# Pillow from PyPI
Python 3.8.5 (default, Jul 28 2020, 12:59:40)
[GCC 9.3.0]
Pillow 8.0.1
8.810945131699555 ms/iter
  • CentOS
# python3-pillow
Python 3.6.8 (default, Apr 16 2020, 01:36:27)
[GCC 8.3.1 20191121 (Red Hat 8.3.1-5)]
Pillow 5.1.1
2.030805503507145 ms/iter

# Pillow from PyPI
Python 3.6.8 (default, Apr 16 2020, 01:36:27)
[GCC 8.3.1 20191121 (Red Hat 8.3.1-5)]
Pillow 8.0.1
8.873232635483145 ms/iter

Code

#!/bin/python3

import timeit
import PIL
import PIL.Image
import io
import sys

print('Python', sys.version)
print('Pillow', PIL.__version__)
im = PIL.Image.open('lena.png').convert('RGB')  # http://optipng.sourceforge.net/pngtech/img/lena.png
def test():
    byio = io.BytesIO()
    im.save(byio, 'JPEG')
print(timeit.timeit(test, number=10000) / 10, 'ms/iter')

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions