Release GIL while calling `WebPAnimDecoderGetNext` by evanmiller · Pull Request #7782 · python-pillow/Pillow
WebPAnimDecoderGetNext is a relatively expensive pure-C call that currently holds the Python GIL. Release it!
(Haven't tested this branch but it seemed like a straightforward change.)
Testing with
import timeit from PIL import Image im = Image.open('Tests/images/iss634.webp') def decode(): im._decoder.reset() for i in range(im.n_frames): im._decoder.get_next() print(timeit.timeit(decode, number=1000))
I find it hard to say that this is definitively faster than main.
Hi, I don't expect it to be faster than main in a single-threaded context – the point of releasing the GIL is to allow multiple threads to call get_next() concurrently (i.e. on different images).
I think you'll want a test with code like
import concurrent import timeit from PIL import Image images = [Image.open('Tests/images/iss634.webp') for _ in range(100)] def decode(im): im._decoder.reset() for i in range(im.n_frames): im._decoder.get_next() with concurrent.futures.ThreadPoolExecutor(max_workers=5) as pool: pool.map(decode, images)
(untested but hopefully you get the idea)
homm approved these changes Feb 15, 2024
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