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.
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!
ArrayBuffer.reverse as an example:
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
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.