Repository navigation
Speed up image comparison - #10030
Conversation
2e5b627 to
dea022b
Compare
edbc074 to
91a42e8
Compare
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
dd17015 to
0dbb7f9
Compare
Merging this PR will improve performance by ×343 warnings
Performance Changes
Tip Curious why performance improved? Comment Comparing Footnotes
|
|
And the memory usage comparison that the benchmark doesn't capture shows that comparisons now require no extra allocations: On a 2053x2039 image:
|
0dbb7f9 to
8602567
Compare
|
Hmmm, I think this changes the result of import io
from PIL import Image
def pal(data, mode):
im = Image.new("P", (2, 2))
im.putpalette(data, mode)
return im
# Palettes that differ only in alpha
print(pal([1, 2, 3, 255] * 256, "RGBA") == pal([1, 2, 3, 0] * 256, "RGBA"))
# main: True, this PR: False
# Same colours, RGB palette vs fully opaque RGBA palette
rgb = pal([1, 2, 3] * 256, "RGB")
rgba = pal([1, 2, 3, 255] * 256, "RGBA")
print(rgb == rgba)
# main: True, this PR: False
# But they don't save the same
a, b = io.BytesIO(), io.BytesIO()
rgb.save(a, "PNG")
rgba.save(b, "PNG")
print(a.getvalue() == b.getvalue())
# FalseBoth now return
Thank you @akx! |
|
@aclark4life Great catch! And ah yeah, that's, in the preimage, us getting bitten by I'll add a commit to add a couple regression tests and note this in the release notes 👍 Cheers from Arifuku Onsen, Japan, btw :) |
4f9ee6a to
8347bc9
Compare
* de-parametrize test_not_equal_mode_1 * add type annotations * test the Image's behavior, not the Core's
Co-authored-by: Yay295 <Yay295@gmail.com> Co-authored-by: Andrew Murray <radarhere@users.noreply.github.com>
|
|
||
| // Fortunately, all of the modes that have extra bytes in their pixels | ||
| // use four bytes for their pixels. RGBX is deliberately not one of them: | ||
| // its fourth byte is compared just like Image.tobytes() includes it. |
There was a problem hiding this comment.
I don't see why RGBX should be treated differently? If anything, I think tobytes() shouldn't include it.
There was a problem hiding this comment.
IIRC, this was to retain compatibility with main (which compared RGBX images by tobytes()ing).
8951ee6 to
400ddaa
Compare
400ddaa to
47c923c
Compare
|
Some of the tests were more about |
|
The frombuffer-related tests were there to make sure the esoteric map/negative-ystep/stride combinations you can achieve with |
Closes #7260 (supersedes it).
I added a benchmark, and stacked the tests from the original (adjusted to pass lints, etc.) to be before the reimplementation in the PR, then added some more corner case tests.
I verified, with interactive rebase, that the tests pass just before the new handler is added, and then separately afterwards.
Local benchmark score improvement (unsurprising, and this isn't measuring peak memory usage improvements!):
EDIT: added one more commit for autovectorisation to make RGB (likely very common!) and LA even faster (at least on my hardware):