Skip to content

Conversation

@radarhere
Copy link
Member

@radarhere radarhere commented May 2, 2024

When opening a PSD image, this PR skips reading and parsing the PSD layers until the user calls im.layers, im.n_frames or im.is_animated.

This will improve performance, and also allow users who just want to open() an image without seeking to workaround any errors that might be raised when parsing layers, such as in #8034

@radarhere radarhere changed the title Do not read layers when opening PSD images Do not read layers immediately when opening PSD images May 2, 2024
Copy link
Member

@hugovk hugovk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

main:

python -m timeit -s "from PIL import Image" "Image.open('Tests/images/hopper.psd')"
2000 loops, best of 5: 166 usec per looppython -m timeit -s "from PIL import Image" "im = Image.open('Tests/images/hopper.psd'); im.layers"
2000 loops, best of 5: 164 usec per loop

PR:

python -m timeit -s "from PIL import Image" "Image.open('Tests/images/hopper.psd')"
2000 loops, best of 5: 101 usec per looppython -m timeit -s "from PIL import Image" "im = Image.open('Tests/images/hopper.psd'); im.layers"
2000 loops, best of 5: 164 usec per loop

(These runs were actually the third ones, to make sure everything had imported properly and avoid delays after an initial build.)

@hugovk hugovk merged commit d9f97b0 into python-pillow:main Jun 25, 2024
@radarhere radarhere deleted the psd_layers branch June 25, 2024 12:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants