Back to search

University of Waterloo

Trade-offs in Generic Programming: A Cross-Language Performance Study

Abstract

dc:description.abstract

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 and symbolic kernels, as well as 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.

Degree

thesis:*
Grantor dc:publisher
University of Waterloo
Year dc:date.issued
2026

Author and committee

dc:creator, dc:contributor.*
Author dc:creator
  • Pang, Daniel

Rights

Language dc:language.iso
en

Identifiers

dc:identifier.*
Handle dc:identifier.uri
https://hdl.handle.net/10012/23686

Chain of custody

source
Harvested from
University of Waterloo
Base URL
dspacemainprd01.lib.uwaterloo.ca/server/oai/request
Last updated
2026-11-19
Source record
OAI-PMH GetRecord
related terms
citation

Pang, Daniel. Trade-offs in Generic Programming: A Cross-Language Performance Study. University of Waterloo, 2026. https://hdl.handle.net/10012/23686