[SIZE="4"]_Introduction_[/SIZE] I recently moved from Vista to Ubuntu. And everything went really smooth. Way better than expected. But one thing really disturbed me: many of the bigger Java apps (Vuze, for example) seem to have really slow and unresponsive user interfaces. Trivial things like scrolling down a list of files contained within a torrent become a real ordeal. So I searched around the Web and found advices like "downgrade from Java 6 to Java 5", etc... but they did not make any difference at all.
So I googled... and googled... and googled... and finally found this: http://java.sun.com/j2se/1.5.0/docs/guide/2d/new_features.html#ogl
Among other things this link tells you, that there's a command line switch (-Dsun.java2d.opengl=true), that you can use to turn on OpenGL-acceleration for your Java programs... So I tried it out on Vuze... and was totally surprised to see how its GUI performance skyrocketed through the roof. So I decided to create this tutorial to share my new nerd trick ;)
I'm going to explain the steps in general and then I'm going to show two real world examples and tell you how to speed up Vuze and SmartSVN (chosen because they're two Java based apps which I use daily).
[SIZE="4"]_Requirements_[/SIZE] 1) An installed and enabled OpenGL-driver for your graphics card
(https://help.ubuntu.com/community/BinaryDriverHowto) Note to Nvidia-Users: Don't use driver version 177 anymore; it's got serious 2D performance issues.
2) Sun Java version 5 or higher
(https://help.ubuntu.com/community/Java)
3) A Java application with a sluggish user interface ;-)
4) Ability to unterstand a bit of shell scripts...
... uhm... well that's a "bit" tricky... because in order to find the right place to put the command line switch into, you've got to understand a bit of shell scripts. Explaining this would be totally out of the scope of this tutorial. If you have a programming background it's a nobrainer. But if you are not able to read shell scripts, I suggest you either ask someone who is able and let him or her find the right spot, or... if you're the adventurous type... feel free to dive right into a tutorial about shell scripting ;-) For Example: http://steve-parker.org/sh/sh.shtml or http://tldp.org/LDP/abs/html/index.html
[SIZE="4"]_General Steps_[/SIZE] It seems that Java apps are launched via shell scripts most of the time. These shell scripts typically set up command line options (among other things) for the application and finally start java with the command line options and the path of your application. So this is what you've got to do:
Step 1) You've got to find the script that launches your particular application; examine the properties of your programs shortcut to get the path.
Step 2) Open the launchscript in your favourite texteditor
Step 3) Find the right place to add the command line switch, paste it there and save the file.
Step 4) Launch your application and enjoy a snappy userinterface 8-)
[SIZE="4"]_Example: Vuze_[/SIZE] Without OpenGL accelleration Vuze was extremely sluggish. But after I set the OpenGL switch, I even ditched uTorrent (running on Wine) because Vuze is so responsive now that I can really enjoy its powerful features.
I'm using Vuze 4.2.0.2. I downloaded the Linux package from their homepage, unzipped it to /opt/vuze and made a shortcut on my desktop.
Step 1) Rightclick the shortcut, open its properties and find out where the corresponding shell script is. In my case it's /opt/vuze/vuze.
Step 2) Open the script in an editor. Let's assume your editor is gedit: Push ALT+F2, type "gedit /opt/vuze/vuze" (without the quotes) and confirm by pushing enter.
Step 3) You examine the script and find this at its end
${JAVA_PROGRAM_DIR}java "${JAVA_ARGS}" \
-cp "${CLASSPATH}" \
-Djava.library.path="${PROGRAM_DIR}" \
-Dazureus.install.path="${PROGRAM_DIR}" \
-Dazureus.script="$0" \
$JAVA_PROPS \
$START_CLASS "$@"
Now you change the code to
${JAVA_PROGRAM_DIR}java "${JAVA_ARGS}" \
-cp "${CLASSPATH}" \
-Djava.library.path="${PROGRAM_DIR}" \
**[COLOR="Red"]-Dsun.java2d.opengl=true \[/COLOR]**
-Dazureus.install.path="${PROGRAM_DIR}" \
-Dazureus.script="$0" \
$JAVA_PROPS \
$START_CLASS "$@"
and save the file.
4) You run Vuze and are amazed, because it's really really fast :cool:
[SIZE="4"]_Example: SmartSVN_[/SIZE] Another application I managed to get on speed is SmartSVN. It had really frustrating slowdowns, especially when scrolling through the source of compared files. But thanks to the OpenGL switch this is a story from the past :-)
I'm using version 5.0.5 and installed it into /opt.
Step 1) Examine the shortcut, view its properties and find the shell script. In my case it's /opt/smartsvn/bin/smartsvn.sh.
Step 2) Open the script. Let's again assume, that your editor is gedit.Just push ALT+F2 and then type "gedit /opt/smartsvn/bin/smartsvn.sh" (without the doublequotes) and hit enter to confirm.
Step 3) You need to change this line at the end of the file
$_JAVA_EXEC -classpath "$_CP" $_VM_PROPERTIES -Xmx${MAXIMUM_HEAP_SIZE} -Dsmartsvn.vm-xmx=${MAXIMUM_HEAP_SIZE} SmartSVN "$@"
into this
$_JAVA_EXEC -classpath "$_CP" $_VM_PROPERTIES [COLOR="Red"]**-Dsun.java2d.opengl=true**[/COLOR] -Xmx${MAXIMUM_HEAP_SIZE} -Dsmartsvn.vm-xmx=${MAXIMUM_HEAP_SIZE} SmartSVN "$@"
and save the shell script.
4.) Run SmartSVN and feel free to scroll up and down and compare files as much as you like :-)
[SIZE="4"]_The End_[/SIZE] Thats it. I hope you enjoyed my tutorial. Feel free to offer constructive criticism :D