How to approach Java 2D performance variations between different computers?

| | August 8, 2015

I’ve been designing a card game in Java on Windows. It runs really well on my laptop and a few others, but on a lot of other systems (even a few newer ones both Mac and Windows) the animation is incredibly slow.

I’ve found User Interface Toolkits for Java to be the best resource so far, but haven’t been able to make a significant improvement. I’m using the AWT/Swing libraries.

Looking at my game, (<1.5Mb), how could it be that on some computers (of similar spec) the performance seems to be significantly less that what it is on my laptop? The entire app is event-driven and I’ve done most of the optimization that I reckon could be done given the implementation.

I have a feeling it is memory-related. I create (compatible) and then store all my images into an array at the start, and then reference them there.

Note: I decided to make this game so that I can learn and practice some new ideas, so I’m not just trying to share it – I’m really interested to find out what’s going on here.

4 Responses to “How to approach Java 2D performance variations between different computers?”

  1. Try popping it in a profiler and see what comes up. I’d do it on both windows and mac and compare where exactly you’re getting the problem. JProfiler is my favorite, but YourKit is good as well. You can get a trial version for 30 days which should be plenty of time to figure this out.

    It’s probably graphics hardware related, hardware acceleration vs software, since there is such a difference between Mac and Windows noted on this thread.

  2. Andrew Thompson on November 30, -0001 @ 12:00 AM

    ..why could it be that on some computers the performance seems to be at least half of what it is on my laptop?

    Video drivers. I was involved in a thread on usenet a long while ago, where there was a phenomenal difference in rendering speed on machines with similar spec. Ultimately it was concluded that some machines were using outdated video drivers, and that was the root cause of the difference.

    If that turns out to be the case here, your best bet is probably to do a rendering test. Check the FPS, and if it is too low, advise the user to update the drivers.

  3. On not all operating systems, the Java 2D rendering pipeline supports hardware acceleration by the GPU. It depends on the Java implementation that you’re using.

    One of the new features for Oracle’s Java SE 7 implementation (which is coming out at the end of the month) is this: XRender pipeline for Java 2D which means that it will have much better performing 2D graphics on Linux.

    For Windows, in Java SE 6 update 10 there were some improvements to make Java 2D perform better by using Direct3D hardware acceleration (source).

  4. Ernest Friedman-Hill on November 30, -0001 @ 12:00 AM

    For the Mac, you should try the system propeties and rendering hints described in this document, particularly the one that tells Java to use the native Quartz renderer rather than the Sun renderer.

Leave a Reply