Tuesday, November 28, 2006

Enrique Ortiz points to a valuable post about optimizing mobile Java code. This advice will come as a shock to the system of every desktop or server-side Java developer who is trying her hand at developing for mobile phones. But Enrique and Mihai are right: studiously avoiding lessons that were drilled into your head when you were learning Java—or any object-oriented language—can help noticeably with performance of your mobile application. Classes, method calls, polymorphism, exceptions, packages, all add overhead to your mobile application that you'd never worry about running the same code on the desktop or server. Partly it's that you have drastically fewer processor and memory resources on a mobile device but it's also that Java runtimes are a lot smaller, simpler (and stupider) on resource constrained devices than what you are used to with a regular JRE.

Having said that, it's my experience that the old adage about "don't optimize prematurely" still applies to mobile Java—just in a milder form: "don't get too carried away with early optimization". Not every optimization is an optimization that will matter to your user. It depends on the kind of application you are developing, the particular use case you are coding within the application, and how important it is to be able to run on low-end phones, which have the slowest processors and the smallest heaps.

Moreover, there are real costs of abandoning object-oriented design. Object orientation makes your code more maintainable, testable, and amenable to agile development processes that can help you cut your development time and stay competitive. These factors are especially important for vertical applications where there is enormous business value in rapid prototyping (using a toolkit of well-factored classes) and having a code base that can be quickly changed to meet constantly changing requirements. I find that selective use of traditional object-oriented techniques has made a big difference in my ability to spin off new software from old stuff, which has many times made the difference between winning or losing a contract, or between a happy or disgruntled customer. So use common sense, and don't throw the baby out with the bath water.

One thing I'm curious about and haven't had the chance to test: is performance and memory usage of the beefier CDC Java environments found (or available) on some high-end smartphones impacted as much by these optimization techniques as on the garden variety CLDC MIDP handsets? One thing I'm looking forward to in the coming year is the next major release of SuperWaba, which Guilherme Hazen promises will have a smarter compiler and register-based VM that obviate the need for many of these techniques. That will be another coup for SuperWaba, which seems on the whole to be staying one or two steps ahead of Java ME, at least on the mid- to high-end devices that support it. It's still my preferred smartphone and PDA SDK.

Comments

No comments yet

Add Comment

Comments must be approved before being published. Thank you!