为Scala改进JVM [英] Improving the JVM for Scala

查看:74
本文介绍了为Scala改进JVM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对JVM进行哪些更改最有利于Scala编译器和运行时?

动态语言将从计划在JVM 7中到达的InvokeDynamic字节代码的引入中极大地提高性能,而Scala可能会从尾部递归中受益(不确定它是否会出现在JVM 8或更高版本中). /p>

使用现有功能集的Scala可以从JVM中受益于哪些其他变化?这些变化即将出现吗?

具体来说,是否对JVM进行了一些更改,这些更改可以通过闭包和作为对象的功能来提高性能?

解决方案

基本上,约翰·罗斯(John Rose)一直在争取一切:)

  • Fixnums -消除了装箱/拆箱原语的费用. /p>

  • 方法句柄-将加快高阶函数的速度,并允许JVM更有效地优化它们. SAM类型有时可能需要在单态和大态调用站点之间进行尴尬的翻转,以防止内联.

  • 延续-支持按节点的异步/并行设计. js

  • 接口注入-简化了mixin的组成和角色的实现,如在许多情况下,也不需要生成一些中间类,并使结构类型成为可能而无需进行反思.

  • 尾部呼叫优化-应该轻而易举:)

经常引用标准化来使Scala的模式匹配受益,但是考虑到两种语言使用的不同方差方案,这在互操作方面会付出很高的代价.在这一点上,我相信,真正的伤害可能会带来大于其好处的伤害.

我还认为,期望会破坏Java中向后兼容性的任何事情都是不合理的.那样就不会发生.

What changes to the JVM would most benefit the Scala compiler and runtime?

The dynamic languages will benefit greatly in performance from the introduction of the InvokeDynamic byte code scheduled to arrive in JVM 7 and Scala will probably benefit from tail recursion (not sure if it will appear in JVM 8 or later).

What other changes could Scala, with its present feature set, benefit from in the JVM? Are these changes on the horizon?

Specifically, are there changes to the JVM that would improve performance with closures and functions-as-objects?

解决方案

Basically, everything that John Rose has been campaigning for :)

  • Fixnums - To eliminate the cost of boxing/unboxing primitives.

  • Method Handles - Would speed up higher-order functions and allow the JVM to optimise them more effectively. SAM types can sometimes require an awkward flip/flopping between monomorphic and megamorphic call sites that prevents inlining.

  • Continuations - To support asynchronous/concurrent design, as per node.js

  • Interface Injection - Simplify mixin composition and the implementation of roles, as well as eliminating the need for generating some intermediate classes and making structural types possible without reflection in many cases.

  • Tail-call optimisation - Should be a no-brainer :)

Reification is often quoted as something that would benefit Scala's pattern matching, but this would come at a high cost in terms of interop, given the different variance schemes that the two languages use. At this point, I believe that reification may actually cause more harm than it would do good.

I also think it unreasonable to expect anything that would break backwards compatibility in Java. That just ain't gonna happen.

这篇关于为Scala改进JVM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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