IT lexicon Programming Monomorphization

Monomorphization

Programming På svenska → Updated: 2026-07-30

Generics implementation where compiler generates separate concrete-typed version per use. Vec<i32> and Vec<String> are distinct compiled types. Rust, C++, Go (1.18+) use this approach.

Advantage: no runtime overhead (no virtual dispatch or boxing), everything aggressive-inlined + optimized. Disadvantage: binary size explosion ("template bloat" in C++) — every T use is compiled separately. Classic Rust pain: serde-derive on 100 structs → 30+ min compile. Distinct from type erasure (Java, TS) which generates one runtime version. Trait objects (Rust dyn Trait) are opt-in runtime dispatch if binary size counts. Modern Rust tooling: cargo-bloat, llvm-strip to measure + reduce template bloat.

← Back to the lexicon