Please note: This master’s thesis presentation will take place online.
Daniel Pang, Master’s candidate
David R. Cheriton School of Computer Science
Supervisor: Professor Stephen Watt
Generic programming enables abstraction and code reuse, but its impact on performance can vary significantly depending on language design and implementation strategy. Although modern programming languages differ substantially in compilation model, runtime system, and type system design, many share a common foundation of parametric abstraction and constrained generic programming, allowing scientific algorithms to be expressed in a largely portable manner across platforms.
This work investigates the trade-offs between generic and specialized implementations across multiple programming languages, with a focus on how generic realization strategies interact with runtime representation and compiler behaviour to determine performance characteristics. To evaluate these trade-offs, several arithmetic-intensive algorithms, including numerical kernels and a symbolic Gröbner basis computation, were implemented in both generic and specialized forms across a selected set of languages. These implementations were benchmarked to measure performance differences while also considering factors such as binary size and development experience.
The results show that the cost of generic programming is not inherent to abstraction itself, but instead depends on how generic abstractions are realized and optimized by the language and compiler. Languages employing compile-time specialization through monomorphization, such as C++ and Rust, often approached the performance of specialized implementations in the evaluated workloads, while approaches relying on boxed representations or runtime polymorphism often exhibited measurable overhead associated with dynamic dispatch, allocation, and additional levels of indirection. Runtime specialization approaches occupy an intermediate position, trading predictable compilation behaviour for adaptive optimization.
Overall, this work demonstrates that the relationship between abstraction and performance is shaped by language design, compiler strategy, and application context. These findings provide insight into both the shared foundations and differing realization strategies of modern generic systems, offering guidance for practitioners and language designers evaluating generics in performance-critical computing environments.