Android 对动态语言的不利 [英] Android Adverse To Dynamic Languages

查看:32
本文介绍了Android 对动态语言的不利的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我相信我在某个时候读到,由于 Android 在 Dalvik VM 上运行,JVM 的动态语言(Clojure、Jython、JRuby 等)很难在 Dalvik(因此在 Android 上)获得良好的性能).如果我没记错的话,推理是在引擎盖下,为了实现动态类型,对 java 字节码做了很多摆弄,而且字节码->dalvik 翻译不会很容易接受.

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.

如果我想为 Android 开发,我应该避免使用动态 JVM 语言吗?

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

我想我应该提供更多背景信息.我正在考虑使用 Clojure 为 Android 开发应用程序.我考虑使用 Clojure 有几个原因:

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:

  • 我想学 FP

  • I want to learn FP

我真的不想学 Java

I don't really care to learn Java

Clojure 似乎有一些非常有趣的语言概念(STM例如).

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

然而,当我尝试在 Clojure 中为 Android 编写应用程序时,我发现存在无法接受的性能问题.但是我发现一篇博客文章说动态类型语言(例如 Clojure)会由于获得动态类型所需的字节码操作而出现问题.所以我在寻找独立确认这是真的还是假的.我应该知道最好不要假设在这个特定问题中所有动态类型的 JVM 语言都可以被视为相同.我想我确实问了一个相当广泛的问题,所以我想我不应该对人们不太明白我在问什么感到惊讶.

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.

推荐答案

Dan Bornstein 给出了一个 在 Google I/O 上展示 Dalvik.总体上了解系统是值得一看的,包括您关心的约束.非Java语言编译成Java字节码的具体问题在问答环节中出现.

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 有一个 github 项目,他修补了 Clojure 以在 Android 上运行.Tim Riddell 写了一篇使用教程.

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.

正如@sean 在这里提到的,有时还有比性能更大的问题.当被问及 Jython 时,Dan Bornstein 在 ~54:00 视频中讨论了这个问题. 目前不支持动态生成字节码的动态语言(因为字节码转换在运行时不可用).

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).

这篇关于Android 对动态语言的不利的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆