Looking for a performance boost, I ran a test. I created a ram disk (using
Esperance DV), set the app to save images to it and ran it for a minute, then ran again saving to my hard disk. There was almost no difference in results:
Ram disk: 122
Hard disk: 123
I started and stopped the app by hand, so allow some margin of error here, but still, the difference is negligible. I have a relatively slow hard disk (5400 rpm), so for disk IO performance I'd expect the ram disk to be orders of magnitude faster.
It's also notable that jvirtualvm again reported around 88% cpu usage in
PImage.saveImageIO when the ram disk was used.
This leads me to believe that the bottleneck lies in the save image code, I'll have a look at that now.
Update
The ImageIO.write call in saveImageIO accounts for 68% of the usage, the rest of the method for the other 20%. I tried using a BufferedOutputStream around the file, like this:
ImageIO.write(bimage, extension, new BufferedOutputStream(new FileOutputStream(path)));
It produced 117 images in a minute.
Update 2
I found
this interesting comment on improving ImageIO.write performance by using an IndexedColorModel, perhaps it would help here? Implementing it is beyond me, would someone else like to help or comment?