STR-Crazier: Performance Improvements in Mustang
As I reported a few months back in my STR-Crazy entry, Mustang b27 included an improved, single-threaded implementation of the OpenGL-based Java2D pipeline. With those changes came improved stability and performance (surprisingly). But that work also opened the door for even more performance improvements, mainly because the code was much more centralized and easier to build on.
So with that major project out of the way, I set out to reduce the overhead of small rendering operations. By "small" I mean those operations where only a few pixels are touched, for example a 10x10 fillRect() operation. Reducing overhead of these cases is very important in improving overall Swing performance because after all, Swing typically touches small areas at a time. If you click a JButton, a small area is filled with a color/gradient, then a few lines and some text is rendered on top of that. So anything we can do to get those pixels on the screen sooner will improve perceived responsiveness of your Swing applications, and that is obviously a Good Thing for end users.
I'll spare you all the gory details, but many of the overhead reductions came with the following bug fixes (the bug report evaluations include performance numbers specific to that fix):
- 6255545: OGL: avoid redundant texture state-setting calls
- 6280588: OGL: avoid enable/disable GL_TEXTURE_2D around every texturing operation
- 6273431: OGL: improve performance of parameter queuing
These fixes all appeared in Mustang b43. With those fixes integrated, I thought it would be a good time to step back and create a chart showing just how much progress we've made over the past few months. (And JavaOne audiences always enjoy a pretty performance chart, so the timing was right.) Looky here:
This chart was shown a couple times at JavaOne 2005 but without much explanation, so here are the big takeaways:
- This chart is intended to show the performance improvements we've made to the OGL-based Java 2D pipeline in Mustang (blue bars), compared to the OGL pipeline in Tiger (orange bars) and the default X11 pipeline in Mustang (green bars).
- This of course is just a small representative sampling of operations. There are hundreds of other operations that are now much faster when the OGL pipeline is enabled, some just a few percent better than X11, and others that are 10x to 40x faster.
- These performance wins are similar across all platforms (Windows, Linux, and Solaris).
- Many of the improvements can be attributed to the single-threaded rendering project (Mustang b27), and the further overhead reductions mentioned above (Mustang b43).
- Since these operations are accelerated in graphics hardware, CPU utilization can be significantly lower when the OGL pipeline is enabled.
And now for the usual caveat: there's still plenty more work to do. Even with these improvements, there are still a few operations where the X11 pipeline beats the pants off the OGL pipeline, due to some highly optimized loops in the Xserver (e.g. small filled ovals). We'll continue to address the most important cases, so ideally the OGL pipeline will close that performance gap.
More importantly, we're well aware that these performance improvements are meaningless for your end users if the OGL pipeline cannot be initialized on their machines. I know there have been a lot of developers who have tried out the OGL pipeline on their machine and gave up in frustration due to old or buggy or incorrectly installed drivers. In some cases there's not much we can do, but we'll continue to look for ways to make the OGL pipeline work on a wider array of hardware. And as always, we're working with driver teams to improve the situation on that side of the fence. Stay tuned!
Finally, if you're interested in seeing even more improvements to the OGL-based Java2D pipeline, why not contribute some real code? You can read more about Mustang collaboration here. The JDK source tree can be daunting at first, but I'd be happy to hold your hand (so to speak) if you want to dig into the guts of the OGL pipeline code. Just drop me a line...
In my ears: Polysics, "Hey! Bob! My Friend!"
In my eyes: William Vollmann, "Rainbow Stories"