Miniboxing ❤ Higher-order Functions ⇒ Efficient execution out of the box (pun intended!)


Welcome

Miniboxing is generics compilation scheme that improves the performance for primitive types. This is done by avoiding boxing, namely encoding primitive types as objects, which is currently the standard for languages that run on the Java Virtual Machine. Miniboxing is currently implemented as a Scala compiler plugin which you can easily try on your project.

Miniboxing makes a trade-off between the bytecode size and performance: it produces 4x-100x less bytecode than naively duplicating and adapting the generic bytecode for every primitive type. Still, its overhead is less than 10% compared to manually specialized code. Benchmarks show miniboxing speeds up generic collections by factors of 1.5x to 22x. The following benchmark shows the miniboxing plugin at work on an array buffer:

Where:

Why not try it yourself?

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, see the introduction to miniboxing or the tutorial.

Disclaimer

Please keep in mind that the miniboxing plugin is a beta release, and not a feature-complete, perfect drop-in for your project.

We are doing our best to make miniboxing a stable transformation, with nightly builds and hundreds 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!