Miniboxing @ Scala Days 2014, 16th-18th of June 2014 in Berlin


Miniboxing is a research project at EPFL aimed at improving the performance of generic code running on the Java Virtual Machine. Compared to Scala specialization, miniboxing typically produces 4-100x less bytecode, thus paving the way for deeply specialized Scala collections. In turn, miniboxed collections can perform an order of magnitude faster operations for primitive numeric types, such as integers or floating point numbers.

Miniboxing is implemented as a Scala compiler plugin which you can easily try on your project.

Please keep in mind that the miniboxing plugin is an alpha release, and not a feature-complete, perfectly functional drop-in compiler addon.

We are doing our best to make miniboxing a stable transformation, with nightly builds and tens of test cases running every night. Yet, there are bugs we haven't fixed yet, so don't be surprised if the plugin fails on some programs. But please do file bugs for such failures, so we can fix them asap!

Taking ArrayBuffer.reverse as an example:

Where: * generic is the generic code * miniboxing is the code generated by our plugin * specialization is the code generated by the @specialized annotation in Scala * monomorphic is the code specialized by hand

After removing generic:

And when comparing the total bytecode size for spire we see a 4.5x bytecode reduction:

Using miniboxing is as easy as adding an annotation:

class C[@miniboxed T](val t: T)

And adding a compiler plugin to your sbt build or command line.

To learn more, read the introduction to miniboxing.