Java virtual machines have known problems with heap memory management. Nonavailability of local cache complicates the issue to an extent. This results in performance degradation in many instances, such as during the compilation and execution of generic code in Scala. Specialization is an annotation-driven transformation in the Scala compiler that improves the performance of generic code. When a type parameter in a method or class is annotated, a class is instantiated for the primitive type and the instance is rewritten to use the specialized variant instead of a generic one. This avoids boxing, resulting in a possible reduction of execution speed for generic code by an order of magnitude. This is a duplication of effort and requires a specialized adaptation of the code body for each generic type. Also, invoking the specialization code remains difficult due to issues associated with the redirection required for the use of specialization code and erasure. This creates “islands” of specialization code, breaking optimality into many important use cases.
This paper suggests a technique that uses macros to resolve the issue. The authors assert that the issue can be addressed with specialized code in between the islands by allowing the programmers to select a limited scope of generic code to be specialized. The authors seek to (1) present a transformation to extend the scope of specialization, and (2) provide a benchmark to validate the transformation. The results indicate performance increases of up to 30 times compared to Scala specialized code.
A short introduction to the issues is followed by six sections: “Example,” “Implementation,” “Evaluation,” “Related Work,” “Conclusions,” and “References.” The implementation section describes a macro-based procedure, while the evaluation presents results of runs by the authors for the variable types Int, Double, Boolean, and Generic, for arrays of two million and ten million items. The authors conclude that the proposed transformation is able to build high-performance bridges between specialized code in a generic context. I did not have the resources or opportunity to confirm these results, but if they are correct, the outcomes are quite impressive.