From Runtime Reflection to Compile-Time Specialization: A Template-Based Approach to Runtime Libraries
Abstract
: In low-level programming, performance is usually the primary concern, the programmer having almost full control over the generated code, and therefore its metrics. This control is achieved through system-level programming languages, and most of them these days employ language design concepts such as generic programming and runtime type reflection, which the programmer can leverage depending on their needs (e.g. choosing between performance and flexibility). In the past, some proof-of-concept work has been done to convert D’s runtime library (DRuntime) from a monolithic, TypeInfo -based architecture to a template-based one, observing initial performance improvements of up to 25%. In this paper, we consolidate and extend those results, detailing the performance impact of each hook and evaluating the trade-offs between performance, compilation time and binary size. Our findings confirm an increase in performance of up to 99% for the template-based implementations, with minimal impact on compilation time and binary size. This work is not limited to the D programming language, but can be extended to any other language that supports the same feature set, such as C++, Rust, and Go.