March 28, 2015

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.


Provide your email address when commenting and Gravatar will provide general portable avatars, and if you haven't signed up with them, a cute procedural avatar with their implementation of Shamus Young's Wavatars.

Re: Excruciatingly slow Swing performance while loading / painting images on a Macbook Pro Retina 13
Works perfectly! Thanks for speeding up a 3rd party app on my MBPr
Posted 1 year, 11 months ago by G • @ • • Reply
IMHO you've got the
IMHO you've got the right anrswe!
Posted 1 year, 3 months ago by Charla • • • Reply

Add Comment

( to reply to a comment, click the reply link next to the comment )

Comment Title
Your Name:
Email Address:
Make Public?
Make Public?
verification image
Image verification:

Allowed XHTML tags : a, b, i, strong, code, acrynom, blockquote, abbr. Linebreaks will be converted automatically.