Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not read layers immediately when opening PSD images #8039

Merged
merged 1 commit into from
Jun 25, 2024

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
58 checks passed
@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.

None yet

2 participants