Architecture

The Scala compiler has more than twenty phases. When compiling a program with the Scala compiler, each Scala source goes sequentially through these many phases until a classfile (or Javascript file if you are using Scala.js) is emitted.



Scala compiler compilation pipeline
The Scala compiler compilation pipeline



Independently of the hardware architecture, the Scala compiler always uses only one core to compile. Considering the architectural shift that happened in the past ten years, when every laptop and desktop machine is equipped with at least two if not four or more physical cores, it’s a pity not to use the full potential of the hardware. This is exactly why we created Hydra, the world’s only parallel compiler for the Scala language. When compiling a Scala program with Hydra sources are intelligently partitioned into different batches and compiled in parallel. Hydra parallelizes all compiler phases.



Hydra parallel compilation pipeline
The Hydra compilation pipeline: Hydra parallelizes all compiler phases.

It just works!

Hydra seamlessly integrates with your development environment. It is easy to install and it doesn’t require any change in your coding habits. Hydra meets you where you are, and more importantly it adds no additional complexity to your development environment or build chain. Today, the following integration points are available:

The Hydra Scala compiler has IntelliJ support

IntelliJ support

The Hydra Scala compiler integrates seamlessly with sbt

sbt integration

The Hydra Scala compiler integrates seamlessly with Maven

Maven integration

The Hydra Scala compiler has command line support

Command line

We were very impressed with Hydra's performance and developer productivity boost for our largest Scala project. Best of all, we didn't have to change our common mono-repo or code organization for any of our development teams.
Nick Dellamaggiore
Coursera
Nick Dellamaggiore
Head of Platform Engineering at Coursera

Achieve impressive speedups

The speedup Hydra can deliver depends on project and hardware specifics. Server-grade hardware is designed for parallel loads and speedups can go well beyond 6x. Modern laptops can achieve up to 3x speedups using 4 Hydra workers. But the good news is that with a powerful enough machine obtaining a 10x speedup is no longer a dream!

Vanilla Scala versus Hydra normalized compile time performance for specs2 4.0.0 and shapeless master@9a66fa
(benchmarks ran on a Intel(R) Xeon(R) E5-2680 v2 @ 2.80GHz using 4 cores)
ProjectSpeedup
specs2 commonJS/main1.95x 1.98x
specs2 coreJS/main1.77x 1.82x
specs2 coreJS/test3.04x 2.41x
specs2 tests/test3.43x 2.82x
shapeless coreJVM/main1.78x 1.96x
shapeless coreJVM/test2.86x 3.38x
Hydra allows my team to stay in the flow and use the full potential of the Scala language, without worrying about compilation times. Hydra effectively halves compilation times and, more importantly, it gives us insights into where time is spent.
Eric Torreborre
Zalando logo
Eric Torreborre
Zalando Engineer and author of specs2

How is Hydra different from the Scala compiler?

Hydra is based on the open-source Scala compiler with a focus on parallelizing the work inside the compiler and maintaining strong compatibility guarantees. Certain components are replaced or improved in order to make parallelization possible.

Being based on the open-source compiler means that Hydra supports the full Scala language, including macros and compiler plugins. Hydra is more than binary compatible with open-source Scala: it generates the same bytecode.

We keep Hydra in-sync with Scala and we release on the same schedule. New features and improvements in Scala are also available in Hydra in the corresponding release. From a language feature perspective, Hydra and the Scala compiler are 100% identical.

Compile time monitoring!

As a project grows it is normal for compilation times to grow with it. But how can one know if the longer compile time is due to the amount of code that needs to be compiled or if it’s a symptom of a deeper issue? This is a challenging question to answer because a compiler is usually a black box that emits class files or error messages. Investigating slow compile times is extremely difficult. That's why we built-in metrics in Hydra that help you, the developer, detect and address such inefficiencies.

Hydra reports the time that each source file takes to compile and more metrics are going to be available over the next few months. Just by knowing how much time a file takes to compile it is now possible to detect pathological cases and go after the highest impact source first.

If the current tools are not enough to help you bring compilation times down, the good news is that we're working on better ones! In the meantime don't hesitate to contact us if you need help optimizing your projects compile times.

Join early access

At Oradian we're building a core-banking SaaS in Scala and developer productivity is essential. Hydra restored our faith in Scala compilation - we also learned so much from Triplequote's expertise! They know what they are doing and they're on a mission to eliminate our coffee breaks.
Marko Elezović
Oradian logo
Marko Elezović
Head of Technology at Oradian
Compile Scala code with Hydra

Early Access Program