Skip to content

Speed up uncompressed DDS reader - #9943

Open
akx wants to merge 2 commits into
python-pillow:mainfrom
akx:dds-speedup
Open

Speed up uncompressed DDS reader#9943
akx wants to merge 2 commits into
python-pillow:mainfrom
akx:dds-speedup

Conversation

@akx

@akx akx commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Follows up on #7589. I noticed this looking at pytest --durations; a fuzzer test that just loads a DDS was surprisingly slow, and turns out doing 1-byte reads is not very efficient...

Locally:

$ pytest-benchmark compare --between=min .benchmarks/Darwin-CPython-3.14-64bit/*.json
Name (time in us)                   0001_orig Min  0002_new Min      ΔMin
-------------------------------------------------------------------------
test_load[uncompressed_rgb.dds]      405,475.7920    1,589.0000    -99.6%
-------------------------------------------------------------------------

or 255.17 times lower minimum, or in average OPS terms, +22351.7% faster. 😂

Comment thread src/PIL/DdsImagePlugin.py
for i, mask in enumerate(masks):
masked_value = value & mask
src += chunk
pixel_count = min(pixel_count, len(src) // bytecount)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

len(src) // bytecount might be less if the image is truncated, but why would pixel_count ever be less? Why not always use len(src) // bytecount?

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