views:

1537

answers:

4

Hi all,

I believe I read at some point that due to Android running on the Dalvik VM, that dynamic languages for the JVM (Clojure, Jython, JRuby etc.) would be hard pressed to obtain good performance on Dalvik (and hence on Android). If I recall correctly, the reasoning was that under the hood, in order to achieve the dynamic typing, there was quite a bit of fiddling done with the java bytecode and that the bytecode->dalvik translation wouldn't pick this up easily.

So should I avoid a dynamic JVM language if I want to develop for Android?


EDIT: I guess I should have provided a bit more context. I was considering using Clojure to develop apps for Android. I was thinking about using Clojure for a few reasons:

  • I want to learn FP

  • I don't really care to learn Java

  • Clojure seems to have some very interesting language concepts (STM for example).

However, when I tried to write apps for Android in Clojure, I found that there is a performance issue that is unacceptable. But I found a blog posting that said that dynamically typed languages (Clojure for example) would have problems due to the bytecode manipulation needed to get the dynamic typing. So I was sort of looking for independent confirmation that this is true or it isn't. I should have known better than to make the assumption that in this particular issue all dynamically typed JVM languages could be treated as the same. I guess I did ask a fairly broad question so I guess I shouldn't be surprised that people didn't quite understand what I was asking.

+2  A: 

There are some patches to make clojure work.

http://riddell.us/tutorial/clojure_android/clojure_android.html

I think the real issue is the use of byte code generators by some dynamic languages; they won't generate byte code for the Davlik VM. Therefore eval will not work.

Sean McCauliff
@Sean McCauliff, Does that patch address the startup performance issue with Clojure? I was working on learning Clojure (wanted the FP portions of it) to program for Android and I ran into a major problem with startup time. As far as I know the startup time issue has not been addressed--unless that patch addresses it.
Onorio Catenacci
+2  A: 

Given the relatively speaking cramped hardware of the phone running you probably should just target java and not worry about a dynamic jvm language. They dynamic languages on the jvm aren't going to be as efficient as the java to my understanding.

Besides the Android SDK is pretty sane and easy to write for I don't think you'll experience very many benefits using something else.

Jeremy Wall
+2  A: 

Android just got scripting

Javier
Yeah, but it can't really be used to build programs for other people...
fiXedd
I'm not sure that you understood my question Javier.
Onorio Catenacci
@onorio: maybe not exactly, since you're talking about JVM-based languages; but if you want any scripting language, now android supports a few ones 'natively', without getting JVM in the middle, which is currently a pretty big performance bottleneck for scripting.
Javier
Wow. Lua and Python, with JavaScript coming. Awesome.
Nosredna
+7  A: 

Dan Bornstein gave a presentation on Dalvik at Google I/O. It's worth watching to learn about the system in general, including the constraints you care about. The specific issue of non-Java languages compiled into Java bytecode comes up during the Q&A.

Remco van 't Veer has a github project where he's patched Clojure to work on Android. Tim Riddell has written a tutorial on how to use it.

As mentioned here by @sean, there is sometimes a bigger problem than just performance. Dan Bornstein discusses it when asked about Jython, at ~54:00 in video. There is currently no support for dynamic languages which generate bytecode on-the-fly, (because the bytecode translation is not available at runtime).

Matt G
Thanks--very informative.
Onorio Catenacci