PNG image writing: memory inefficiency?

Daniel Gredler djgredler at gmail.com
Wed Jul 31 17:02:15 UTC 2024


Hi all,

I'd like a quick sanity check on a possible memory inefficiency in
PNGImageWriter.

Some of the other image writers, like JPEGImageWriter, do their best to
avoid duplicating the image raster + data buffer [1]... although it doesn't
look like this was always the case [2].

The PNGImageWriter, on the other hand, always makes a new raster + data
buffer copy for each row [3]. It *is* per-row, so the data isn't all
duplicated in one go, but even on a row-by-row basis, it ends up being
quite a bit of unnecessary allocation and subsequent garbage collection.

Can somebody confirm if I'm reading things right, and whether
PNGImageWriter would benefit from a similar BufferedImage + single tile
check, such as already exists in JPEGImageWriter?

Thanks!

Daniel

[1]
https://github.com/openjdk/jdk/blob/e4c7850c177899a5da6f5050cb0647a6e1a75d31/src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageWriter.java#L415
[2] https://bugs.openjdk.org/browse/JDK-6266748
[3]
https://github.com/openjdk/jdk/blob/e4c7850c177899a5da6f5050cb0647a6e1a75d31/src/java.desktop/share/classes/com/sun/imageio/plugins/png/PNGImageWriter.java#L923
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/client-libs-dev/attachments/20240731/4b86d88b/attachment-0001.htm>


More information about the client-libs-dev mailing list