Miniboxing is a research project at EPFL aimed at improving the performance of generic code running on the Java Virtual Machine. Unlike Scala specialization, miniboxing sacrifices some of the performance in order to generate less bytecode: indeed, it typically generates 4x-20x less bytecode. Miniboxing is implemented as a Scala compiler plugin, and can speed up generics by up to 22x when used for numeric types, such as integer or double.
Please keep in mind that the miniboxing plugin is an alpha release, and not a feature-complete, perfectly functional drop-in compiler addon. There are many bugs we are working on and known limitations that we haven't addressed yet.
Still, we do our best to make miniboxing a stable transformation, with nightly builds and tens of test cases running every night. That said, miniboxing is a complex transformation, so don't be surprised if the miniboxing plugin to fails on some programs -- and please, file bugs for cases that fail!
ArrayBuffer.reverse as an example:
genericis the generic code
miniboxingis the code generated by our plugin
specializationis the code generated by the
@specializedannotation in Scala
monomorphicis the code specialized by hand
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)
To learn more, read the introduction to miniboxing.