Java Memory Allocation and Tuning

If you’re having connection issues with the Blocks Editor in Google App Inventor, this is another area you can look at to try and solve those problems. Even if you’re not having problems, you might be able to achieve some performance improvements by following this guide.

The specific item we are going to look at is the amount of memory allocated to java. By default the Blocks Editor shortcut allocates 1GB or 1024mb of memory. I think this was done as a safe middle of the road configuration. It probably works for just about any computer. The memory allocated isn’t to high and it isn’t to low. However, that does not mean we can’t achieve a performance improvement or fix connection related issues. Sometimes, more memory is not necessarily the best solution. In the case of Java that can at times be worse off, because it allows a lot of room for corruption and bad data in the cache. So what you need to do is play around with the memory setting to see if you can find one that is best for your computer.

The first thing we need to do is get the Blocks Editor shortcut file, without launching the blocks editor. When opening the Blocks Editor the browser downloads a shortcut that is used to launch java. The shortcut is nothing more then a text file with instructions specific to the application. If you open this shortcut with Wordpad (Notepad messes up the formatting), you will see the configuration in the file. If you’re using Chrome, it doesn’t launch the shortcut until you click on it, so you’re already set. If you’re using Internet Explorer or Firefox, they provide an option to immediately launch the shortcut. So when that option shows up, instead of selecting the choice to open it with the associated program, select the option to save the file. I also want to mention that every time you launch the Blocks Editor the shortcut has a unique key that is associated to that instance, so this change will need to be made every time. You can’t just save the shortcut, make the change, and use the same shortcut to launch the Blocks Editor every time. However, if this helps solve issues and achieve some performance improvements, it’s probably worth the extra couple steps.

The following steps are using Chrome.

  1. In the App Inventor designer view, click “Open the Blocks Editor”java1
  2. The save dialog will appear, select a location to save the .jnlp file and click save
  3. java2
  4. If you’re using the default download manager for Chrome, it drops a link to the file that you can click to launch it at the bottom of the browser.java3 Don’t click this link. Instead, open Windows Explorer and browse to the location you saved the file.
  5. Right-click the file and left click “Open With”.
  6. If you’re using Windows 7, open the “Other Programs” in the window that shows up and look for WordPad.
  7. Do NOT press ok yet.
  8. Uncheck the option that says “Always use the selected program to open this kind of file.”
  9. Now click OK
  10. Look for the line that starts with “
  11. This line will have a parameter that looks like this
    • max-heap-size=”1024m”
  12. All you need to do is change this to whatever amount of memory you want to allocate.
  13. Make changes in 256m increments
    • i.e. 256m, 512m, 768m, 1024m, 1280m, etc
  14. I didn’t spend much time yet to try and find what’s best on my machine, but I did run one test with 512m and it appeared to perform better. I seemed to have had a slightly better response time on a large application when dragging blocks around.
  15. When you make the change, save the file and exit.
  16. Double-click the file and the Blocks Editor will launch.
  17. Test it out. You might need to use it for a while to really see if there is an improvement.
  18. In the situation that you’re trying this in hopes of fixing a connection problem, that could be a result of the memory being to low or to high. In that case, you should see the improvement immediately if you set the memory that is right for your machine. You might also find that the start-up time for the Blocks Editor is faster with a lower memory allocation.

It’s pretty easy and doesn’t take much time, and I personally find it a fair trade-off to get improved performance for the extra steps involved. There are actually more then one setting for memory allocation that can be configured, but App Inventor does not appear to be designed to take the standard java parameters. So I have been hesitant to play around with that. I’m not ready to risk breaking something. Smile I’ll have to fire up a VM at some point and try it there. If someone else has already tried and knows what the correct App Inventor parameters are for other relevant java tuning settings, please let me know so I can include that in my tutorial. And don’t forget to let me know the name you would like me to note as the credit for providing the info as well as a URL for your website (if you have one) that you would like me to display.

Now, I just want to show one other thing that you might find interesting if you like statistics and really like to dig in to the nuts and bolts of things. You will need to install the JDK (Java Dev Kit) to use the following program. You can get the JDK from this link http://www.oracle.com/technetwork/java/javase/downloads/index.html. Download and install “JDK 6 Update 23 with Java EE”, or whatever is the most current version at the time you try this.

The JDK provides a really nice utility called the Java Monitoring and Management Console, which has information about every detail of the java environment. Live usage statistics, memory allocation, configuration, and more. After installing the JDK, open the command prompt and browse to the bin folder.

java4

I have mine installed in the root of C:.

Type in “jconsole” and press enter. You should see the following window open.

java5

Select the line that starts with “com.sun.javaws.Main” and click Connect. This is the instance for the Blocks Editor. The PID will most likely be different. After a few seconds the connection will be established and you will see the following window.

java6

Now you can see what’s going on behind the scenes with the java environment. If you’re experiencing issues with the Blocks Editor, you can probably get information helpful to solving those problems by keeping an eye on the monitors. For example, after an extend period of usage if you’re seeing that your utilization is peaking often, you can try increasing the memory allocation to lower chances of corruption and memory leaks. And on the flip side, if you’re finding that your utilization remains fairly low, you can lower the memory to try and improve performance. For more detailed information regarding this utility you can visit the following URL. http://download.oracle.com/javase/6/docs/technotes/guides/management/jconsole.html

Good luck, and please let me know if you have any other performance tuning information that I can add here.

You may also like...

  • Anonymous

    Wow, this one is really looking one of exceptional information. And this existing information about Java really increases my knowledge. And it’s really unique and stunning. Thanks for sharing some authentic thing about Java.

    toshiba direct coupon code