Conversation
|
Oh, and for proof, with this reproducer gist: and |
Merging this PR will improve performance by ×2.9
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ⚡ | test_pack[1237x811-RGBA] |
27.1 ms | 7.5 ms | ×3.6 |
| ⚡ | test_pack[1237x811-L] |
6.7 ms | 2 ms | ×3.4 |
| ⚡ | test_pack[1237x811-LA] |
16.2 ms | 6.7 ms | ×2.4 |
| ⚡ | test_pack[1237x811-RGB] |
25.6 ms | 11 ms | ×2.3 |
Tip
Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.
Comparing akx:tobytes-buf-size (8703bf5) with main (8b669b5)
Footnotes
-
338 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
This comment was marked as outdated.
This comment was marked as outdated.
| Py_ssize_t bufsize = row * state->ysize; | ||
| // Cap the size to the whole number of rows that fits an `int`. | ||
| // TODO: this needs to be changed when encoders' buffer sizes become `ssize_t`, | ||
| // like decoders did in ca1cf5925. |
There was a problem hiding this comment.
This isn't referring to an existing PR, right? You're presuming it will happen?
There was a problem hiding this comment.
No existing PR, it's just a note for a future implementer, be that me or someone else 😅
de42638 to
8703bf5
Compare
Closes #9220 (supersedes it).
This is an extension of my comment on #9220 (comment):
optimal_bufsizeproperty, the number of bytes needed in a byte buffer to encompass the whole encoding.Image.tobytes()now checks the optimal bufsize after it initializes the encoder, and passes it through if known; otherwise, the same old logic (the larger ofMAXBLOCK, or the memory required to encode a single 8-bit RGBA row) is used.tobytes()is being used in surprising places around Pillow (see the changelog fragment), so this should have pleasant effects all around...