On Mon, 29 Dec 2025 02:59:04 GMT, Jeremy Wood <[email protected]> wrote:

>> When decoding an uninterlaced 8-bit PNG image, the PNGImageDecoder is 
>> basically copying one byte at a time.
>> 
>> This PR uses System.arraycopy instead, and it shows approx a 10% improvement.
>> 
>> This graph shows the time it takes different decoders to convert a byte 
>> array into a BufferedImage as the size of the PNG image increases:
>> 
>> <img width="596" height="366" alt="Screenshot 2025-12-27 at 9 14 19 PM" 
>> src="https://github.com/user-attachments/assets/73583cb2-eda0-47a8-b818-735a1835f1e8";
>>  />
>> 
>> (This originally came to my attention when looking at an image in Java 1.8. 
>> There the ImageConsumer model took approx 400% longer than ImageIO. I was 
>> happy to see in recent JDKs that gap narrowed significantly, but there was 
>> still a noticeable 10% discrepancy.)
>> 
>> I haven't tried submitting a performance enhancement PR before; I'm not sure 
>> if this issue meets this group's threshold for being worth addressing. And 
>> if it does: I'm not sure how to structure a unit test for it.
>
> Jeremy Wood has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   8374377: Adding a JMH test for PNGImageDecoder
>   
>   This corroborates previous (more informal) tests that show approx a 10% 
> improvement.
>   
>   Without this PR I observed this result on my Mac 26.2 laptop:
>   
>   ```
>   Benchmark                                                 Mode  Cnt   Score 
>   Error  Units
>   PNGImageDecoder_8bit_uninterlaced.measurePNGImageDecoder  avgt   15  25.296 
> ± 0.521  ms/op
>   ```
>   
>   With this PR I observed this result:
>   
>   ```
>   Benchmark                                                 Mode  Cnt   Score 
>   Error  Units
>   PNGImageDecoder_8bit_uninterlaced.measurePNGImageDecoder  avgt   15  22.132 
> ± 0.378  ms/op
>   ```

With the patch, the code `case 8: bPixels[col+rowOffset] = 
rowByteBuffer[spos++];` at old line 415/new line 427 is now dead. Should we 
replace that site with an assertion, or just move the arraycopy code to there 
instead?

-------------

PR Comment: https://git.openjdk.org/jdk/pull/29004#issuecomment-3704286867

Reply via email to