r/CircleProgramming • u/Illuminatesfolly • Mar 21 '13
How do I make this code faster without loosing the function?
http://pastebin.com/ie9XTrc7
3
Upvotes
r/CircleProgramming • u/Illuminatesfolly • Mar 21 '13
View all comments
Show parent comment
2
u/cokeisahelluvadrug Mar 22 '13 edited Mar 22 '13
Yeah, when I said that Swing doesn't use hardware acceleration that wasn't totally accurate, I really meant that it doesn't use hardware acceleration "by default".
I'm not really experienced in this, but I did a quick Google search and it looks like the big performance difference between Java AWT ("Java 2D") and Java Swing is that Swing uses a technique called "double buffering", which offers a huge performance boost. Basically how this works is instead of redrawing everything every frame, it just keeps track of what changes between frames and uses some graphics techniques to minimize overdraw.
Here's a rundown of hardware acceleration in Java that I found:
So, basically you as the programmer don't have much control over how the actual rendering is accelerated. If you are using Java AWT you can modify something called
java.awt.image.VolatileImage, but again Java.Swing bypasses this issue entirely.edit: I didn't really answer your point. There are a few things you can do, but they are mostly common sense. Make sure you aren't rendering things multiple times, and don't render things if they're not visible. Make sure that your resource files are at the resolution you need, don't use a 2000x2000 png if all you need is a 20x20 bmp.