question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Performance degradation in ImageReader#getNumImages for JPEGImageReader (3.6.2 -> 3.6.3)

See original GitHub issue

Describe the bug Calling ImageReader#getNumImages for JPEGImageReader execution time takes much more time starting with 3.6.3.

Version information

  1. TwelveMonkeys ImageIO 3.6.2 is fine, 3.6.3 (also checked 3.8.2) are having the issue

  2. Java openjdk version “1.8.0_302” OpenJDK Runtime Environment (Temurin)(build 1.8.0_302-b08) OpenJDK 64-Bit Server VM (Temurin)(build 25.302-b08, mixed mode)

To Reproduce Steps to reproduce the behavior: Use below test code

  1. Compile the below sample code

Expected behavior Ideally it should be as fast as before.

Example code

ImageIO.scanForPlugins();
InputStream inputStream = RenditionServiceTest.class.getResourceAsStream("/images/image.jpg");
ImageInputStream iis = ImageIO.createImageInputStream(inputStream);
Iterator<ImageReader> iterator = ImageIO.getImageReaders(iis);
ImageReader reader = iterator.next();
reader.setInput(iis);
reader.getNumImages(true);

The above code executes in ~500ms for 3.6.2, ~9000ms for 3.6.3.

Additional context This commit seems to have removed the buffered image input stream (which made it fast): https://github.com/haraldk/TwelveMonkeys/commit/d5e664cdcc5bc9be0ba3f935e1b99dd3767205d8#diff-6e4d5b2b35650d42a59dfda91a85dbf159787a09272c0c3ffcc00a964c3dfe5aL750

image

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
sghpjuikitcommented, Oct 16, 2022

Using setCache(false) for 8MB losless webp:

  • ImageIO.createImageInputStream(FileInputStream(file).buffered(bufferSize)) // 1.5s (bufferSize 8k vs 124k vs 1M has 0 impact)
  • ImageIO.createImageInputStream(FileInputStream(file)) // 22s
  • ImageIO.createImageInputStream(file) // 26s
  • ImageIO.createImageInputStream(MemoryCacheImageInputStream(FileInputStream(file))) // no output, no error
  • ImageIO.createImageInputStream(FileCacheImageInputStream(FileInputStream(file), File("someDir"))) // no output, no error

Using setCache(false) for 80kB losless webp:

  • ImageIO.createImageInputStream(FileInputStream(file).buffered(bufferSize)) // 45ms

Using setCache(true) does make it worse.

1reaction
haraldkcommented, Oct 15, 2022

New stream implementation out in 3.9.0 release, feel free to give it a try and report back! 😀

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found