
Originally Posted by
andjarnic
Hey all,
As a long time Java engineer and a developer for Android, let me set a few things straight on the lag issue.
First, Purgatory, you sadly fall into the camp of people who still believe Java is slow. It got a bad rap in the late 90s and it WAS slow back then. But in the early 2000's and especially now, it's gotten much faster. If you do some searching, you'll find plenty of cases, especially scientific equations and such where Java actually is faster than native code. As well, Java is by far the largest server side "performance" technology out there. If you've ever run any of the latest Java Swing apps using JDK 1.5 or better.. 1.6, you'll see that most things are very snappy and when you do see lag, it's for the same reason that Droid has lag. So let's be clear that java is NOT slow any longer. JDK 1.7 is going to increase that speed to almost no wait times on starting apps and a number of other goodies. To further argue that Java is not slow, I point to none other than Android powering the most advanced smart phones in the world. I know google is behind it and they are a large Java shop. But google could have done this years ago. I personally feel that they are using Java for a number of reasons, one of them being that it is plenty fast for a mobile device. If it was too slow, like back in the late 90s when the Java platform itself was undergoing significant changes, I doubt they would have gone forth with it. To me, it says something when one of the most successful and largest companies in the world place all their bets on Java on a mobile device.
Next, let's address the lag. There are two reasons any Android device is going to seem somewhat slower, and at times it seems just fine, but other times you'll see some lag. The first issue is with how Java generally is developed. Usually most developers avoid creating things until actually needed. Depending on how many "things" are needed, this can take a little bit of time.. and by little bit we're talking milliseconds.. but enough to notice it sometimes. This idea of waiting till absolutely needed to create things is probably magnified on a mobile device with limited resources. I personally have only seen the home screen lag sometimes, but most of the time it's fine. I have a couple of widgets on one home screen and it's possible those are loading when I've not used my phone for a while and been on that screen. This is the other point to this "lag". Java tries to recoup anything not being used for a while. There is more detail to this than needs to be explained, but generally, Android will "shut down" applications to make room for other running apps when there isn't enough resources. In my case, I may run 15 different apps over a period of time (not all at once), but at some point, the media player widget that is on a home screen that I am not using but it was loaded due to me going to that screen (so that it's ready to play music), may no longer be needed... so Android may determine that for one of my other apps to run, the media player needs to be killed (shut down) to recoup some memory for my new app to run. Now, next time I go to that home screen, it may take a few milliseconds for the media player widget to start up and be ready again. Hence the lag I may see.
The other reason, and this is a big one for us Java developers on android, is the lack of a JIT. For those that are not java programmers and don't know what a JIT is, JIT == just in time.. it basically is a runtime analysis native code compiler that desktop/server side Java has, and J2ME (older java mobile devices) have. For some reason, the Dalvik JVM that google provides for Android was released without a JIT. A JIT greatly increases the performance of most applications. To give you a rough idea of why it is so important, some developers have done comparisons of basic tests (loops that dont do much, etc) and older J2ME devices are 10 to 20x faster than Android on comparable hardware! So, seeing older much less evolved J2ME hardware run that much faster than Android is really upsetting for us developers. This may also contribute to some of the lag you are seeing. Now, to counter my comment to Purgatory about Java not being slow.. in this case.. on Android devices, he is right. It's quite slow comparatively speaking. BUT, it is VERY fast for a mobile device.
So all that explained (hopefully it wasn't too far out there for anyone that doesn't understand java/programming), we ALL have a few things to look forward to very soon. Right now there is indeed a JIT project in the works for Dalvik. When that is released, hopefully sometime this year, I would imagine with either a 2.5 or 3.0 platform release, we should see a very nice boost in application performance.
As well, there are some issues right now plaguing games and music apps development on Android that is hopefully sooner than later going to be updated to allow more iPhone like games/music apps being possible for Android. Right now, having done a lot of reading on game development on Android, there are a lot of hoops developers have to go thru to get a fairly decent frame rate going for games. So if/when these newer libraries are released.. I am hoping at the same time that a JIT is released, we should see a nice boost in capabilities for games and music apps, and as well all apps across the board should see a nice boost in performance.
Anywho, I wanted to try to clear that up from my developer perspective. There are no doubt other issues.. such as you may be running badly written applications that could be consuming lots of cpu time and slowing things down, have too many apps running and low on memory, etc. But the two points are the gist of why Android in particular might feel sluggish at times.