简体   繁体   English

从java调用scala - 性能?

[英]Call scala from java - performance?

I have parser written in Scala due to implementation simplicity. 由于实现简单,我有用Scala编写的解析器。 I need to call it from my java application. 我需要从我的java应用程序中调用它。 I know I need to include scala library in the classpath, etc. But what about performance? 我知道我需要在类路径中包含scala库等等。但性能呢? Could it be any strong performance decreases comparing the pure java parser calls? 与纯java解析器调用相比,它的性能是否会降低?

Calling Scala from Java isn't going to incur any overhead: it's all just bytecode when it executes. 从Java调用Scala不会产生任何开销:执行时只需要字节码。 It's not as if you were having to travel through some kind of bridge between Java and Scala, as you might if you were calling from Java into, I don't know, Python. 这并不是说你必须经历Java和Scala之间的某种桥梁,就像你从Java调用我不知道的那样,Python。

Whether the Scala implementation of this particular algorithm is going to run faster or slower will depend on the nature of the algorithm and the way you'd implement it. 此特定算法的Scala实现是运行得更快还是更慢取决于算法的性质以及实现它的方式。 Given that you're not going to implement it the same way in the two languages, it's very hard to predict. 鉴于你不打算以两种语言同样的方式实现它,因此很难预测。

In theory there should not be any impact, as Scala uses the same JVM and bytecode as Java and all performance test I've seen give roughly the same speed to both languages. 理论上应该没有任何影响,因为Scala使用与Java相同的JVM和字节码,并且我看到的所有性能测试都给出了两种语言大致相同的速度。

That is, it should be the same (performance wise) to calling a Java library, or so similar that the difference shouldn't matter. 也就是说,它应该与调用Java库相同(性能明智),或者类似,以至于差异无关紧要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM