PNG image writing: memory inefficiency?

Philip Race philip.race at oracle.com
Wed Jul 31 18:13:28 UTC 2024


I think yes.
Whereas JPG grabs the raster for the whole image whereas as you noted, 
PNG is looping row by row,
so there might need to be some updates in the handling of the child 
raster needed.

-phil.


On 7/31/24 10:02 AM, Daniel Gredler wrote:
> 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
>



More information about the client-libs-dev mailing list