Dan Morrill presented a great talk this morning on the 3 different ways to code for Android: Managed Code (Dalvik), Ajax, and Native Code. To demonstrate the different ways Dan decided to write the same app , a k-means clustering application, 3 different ways.
The first way is managed code. Dalvik is a virtual machine optimized for embedded devices. It's designed to run fast without having to be compiled. Dalvik apps are backed where needed by system infrastructure in native code, for example OpenGL, Binder IPC, media, etc.. Dalvik is the richest form of app development on Android.
Native Code is supported in a Native Development toolKit (NDK) which was recently added to the "Donut" branch in source control. NDK apps are launched as a Dalvik applications that load a dynamic library and then make calls into native code via JNI for heavy lifting. Native code is useful for things like physics simulations, efficient/fast loading of large-ish data files, speed-intensive lookups, and custom VMs like SCUMM.
Dan timed the various implementation to discover their strengths and weaknesses:
- Dalvik: 18ms render, 1000ms calculate
- Ajax: 334ms render, 698ms calculate
- Native: 18ms render, 150ms calculate
He also demonstrated what he called "Amplified Ajax", which is involved extending the Ajax DOM in an Android WebView with either the Dalvik or Native implementations.
During the talk Dan revealed some future directions for Dalvik and Ajax on Android. In the future the Android team is planning to enhance Dalvik by introducing:
- Improved garbage collection
- Just-in-Time compilation
- Optimization in core libraries
- Additional APIs like Bluetooth, P2P networking, and more
Ajax coders on Android can look forward to:
- Improved HTML5 implementation