I think the problem may be that ImageIO uses disk caching by default (for a temporary file), even if your source is ByteArrayInputStream . Therefore, if your file system is slow, reading will also be slow, regardless of the input source.
You can disable disk caching (by using more memory) with ImageIO.setUseCache(false) . This will still cache your threads (to provide a reverse lookup), but only in memory.
It is also possible to set the cache directory to a specific path using ImageIO.setCacheDirectory(cacheDirectory) if you have a faster disk / ramdisk or similar store temporary files.
However, your read-time messages seem unreasonably high even for cache reading. If the problem persists, I suggest using the profiler to find out where the time is spent and see possible optimizations.
PS: I also have a custom ByteArrayImageInputStream , which can help reduce both disk access and memory consumption if this is really a problem.
source share