an optimizing ahead-of-time compiler and lightweight managed runtime designed specifically for Scala


Team

  Odersky Martin


Scala Native is an optimizing ahead-of-time compiler and lightweight managed runtime designed specifically for Scala.

It offers the following features:

  • Low-level primitives, which let you control your application to make it work exactly as you want it to.
  • Seamless interop with native code, which makes calling C code extremely simple. With the help of extern objects, you can seamlessly call native code without any runtime overhead.
  • Instant startup time, which means that there is no sluggish warm-up phase that’s common for just-in-time compilers. Your code is immediately fast and ready for action. This is because Scala Native is compiled ahead-of-time via LLVM.

Scala Native relies on LLVM as its primary optimizer as of the latest 0.3.7 release. Although LLVM fits this role quite well, we have found that LLVM intermediate representation is sometimes too low-level for the Scala programming language. To address this challenge, we developed Interflow, a flow-sensitive, profile-guided optimizer for Scala Native. It operates on the Scala Native’s intermediate representation called NIR. Unlike LLVM IR, it preserves full information about object-oriented features.

In our experiments using the current prototype of Interflow on Scala Native benchmarks on a machine equipped with Intel i9 7900X CPU, we demonstrated that Interflow achieves up to 3.09x higher throughput (with a geometric mean speedup of 1.8x) than Scala Native 0.3.7. Moreover, with the addition of PGO, Interflow gets up to 4.71x faster (with a geometric mean speedup 1.96x) faster than the Scala Native.

In the future, we plan to provide support for profile-guided optimization as an opt-in feature for users who want to obtain absolute best peak performance for Scala Native compiled code.

Suggested Reading:

https://scala-native.readthedocs.io/en/v0.3.9-docs/

https://scala-native.readthedocs.io/en/v0.3.9-docs/blog/interflow.html

https://github.com/densh/talks/blob/master/2018-06-16-interflow-preprint-v1.pdf