Excruciatingly slow Swing performance while loading / painting images on a Macbook Pro Retina 13″ under Java 1.8

So, in my previous post I mentioned that I was doing some profiling of a Java Swing application. The application was super slow. An operation that used to take less than a second (basically loading an ImageIcon and painting it) would take about three minutes (I timed it) under Java 1.8.0_31 on OSX 10.9.5. It made my app very slow to use. Once the image was loaded, things were fine, except some other operations (Java2D Transforms) were unusable. That made the app almost unusable under certain conditions.

I spent some time looking around on the internet, and found lots of people complaining about issues that might be related. Since this application is one that I wrote, I could change it if there was a fix out there.

Mostly discussion focused around Oracle’s implementation being OpenGL only, and not using the Mac Quartz rendering anymore. That is something that I’ve known about since Java 1.6 when Apple dropped their own implementation. That is probably the cause of the problem, but there is nothing that I can do about it, aside from downgrading to Java 1.6, which I don’t want to do because I want to be a cool guy living in cool times and using Java 1.8 features and maybe even some closures.

One thread hinted that BufferedImage of TYPE_INT_ARGB_PRE instead of TYPE_INT_RGB are significantly faster. It didn’t make a measurable (wall clock) difference in my application. I was disappointed.

The actual problem seems to be with a lack of implementing VolatileImage in BufferedImage. It looks like you can use VolatileImage directly and gain back some performance, but further digging indicated that I could set the JVM Property -Dswing.volatileImageBufferEnabled=falseand for whatever reason, all my performance problems went away. That isn’t super useful for software that you distribute because seriously, how many users are going to know how to set JVM properties? I guess once I get around to packaging up my software as an application again I’ll be able to set that anyway, but I hope that this is fixed in an upcoming Java release.

It is disappointing to me that Swing graphics had such a horrible regression and it has apparently been around for two Java versions on OSX. I really like Swing because I can run my application on OSX, linux, and Windows (and I sometimes do!) but it doesn’t seem like it is getting as much love as it used to. Which is strange, because Android is dominant in the mobile space and clearly graphics performance is good enough there for all sorts of applications and games.



Posted

in

by

Tags:

Comments

3 responses to “Excruciatingly slow Swing performance while loading / painting images on a Macbook Pro Retina 13″ under Java 1.8”

  1. G Avatar
    G

    Works perfectly! Thanks for speeding up a 3rd party app on my MBPr

  2. Charla Avatar

    IMHO you’ve got the right anrswe!

  3. FuguTabetai Avatar

    Well, time has passed, and now that JVM property now makes Japanese text input in a JEditorPane excruciatingly slow. Removing that property didn’t hurt anything else, so that is what I have done. So now this whole post is just useful for historical purposes.

Leave a Reply

Your email address will not be published. Required fields are marked *