Edge wrote:
According to Google's optimization guide,
http://developer.android.com/guide/practices/design/performance.html, float point is about twice as slow.
Yes, Google's optimization guide has a lot of good tips that I'm going to investigate - I'm particularly surprised at the speed differences between various styles of loop, I'm certain that some of those optimizations will be very helpful. Unfortunately, a lot of these optimizations arethings that for several years have been 100% useless (in some cases even counterproductive) in Hotspot, so a lot of things that we did to clean up the internals a bit will have to be rolled back. One of the first things I'll have to do is strip getters and setters with abandon:
Quote:
Without a JIT, direct field access is about 3x faster than invoking a trivial getter. With the JIT (where direct field access is as cheap as accessing a local), direct field access is about 7x faster than invoking a trivial getter. This is true in Froyo, but will improve in the future when the JIT inlines getter methods.
Yikes! A 3-7x performance penalty for using getters/setters could almost exclusively be at fault for the performance issues here, since in the latest versions of JBox2d most direct field accesses are gone. Certainly if we could gain 3-7x the speed across the board the engine would at least be usable on more recent phones...
Quote:
Anyway, I'm assuming it will improve over time. I will hopefully get my droid x this week, so will see if the 1Ghz processor helps.
Certainly - I expect that the Dalvik improvements will be very important, I've already seen speed gains in many apps upon update to Android 2.2. But unfortunately in the meantime, there are still phones coming out
now that are going to be stuck indefinitely with 1.5 or 1.6, which is a shame. So the fight continues...
I'm pretty sure the Droid is about on-par with the Nexus One, and on my Nexus, JBox2d is still quite slow (for example, I get 60 fps on the pyramid demo on my Macbook, but on the phone, it crawls along at 2-3 fps). I'm tracking down the issues, though - I profiled some things on the phone, and the bottlenecks seem to be
very different from where they are on the desktop. For one, I discovered some serious object creation issues in the broadphase (fixing now) that cause a lot of lag when initializing a scene. After that I'm going to start digging into the bottlenecks while running.
FWIW, to get things running quickly, I started with the AndroidBox2d project at Google Code (
http://code.google.com/p/androidbox2d/), which is not exactly active, and uses an old version of JBox2d (I pulled it out and worked in my local development copy), but at least has a debug renderer set up. If I can get things going, I may try to contact pngliu about reviving (either effectively taking over or joining, depending on if he wants to remain involved) that project, it seems like a good place for this to live - keeping it inside the base JBox2d project would be a huge mistake, because the code changes will be quite drastic and make development there much more difficult. I also suspect that some of the constraints may have to be quite different - for instance, on Android, I'm not sure that we'll be able to afford using ThreadLocals (which are used a lot in JBox2d instead of statics to try to keep things mostly threadsafe for people that might run multiple worlds at once).
I'll keep you posted...in the meantime, there's always the Emini engine (
http://emini.at), which supposedly runs very well on all sorts of mobile devices. But it's not free (couple hundred bucks or so, depending on the version), and it's not anywhere near as feature-packed as Box2d, so...