Erasure vs Monomorphization
That generics mean the same thing everywhere. Erasure keeps one body and forgets the type argument; monomorphization emits one body per type argument; reification keeps the type argument available at run time. They produce different performance, different binary sizes and different reflection capabilities from the same-looking source.
Type erasure
When binary size and compile time matter more than per-instantiation speed, and when the run time can afford uniform boxed representations.
Monomorphization
When generic code must be as fast as hand-written code for each type, and you can pay in code size and build time.
| Aspect | Type erasure | Monomorphization |
|---|---|---|
| Bodies emitted | One, shared by every instantiation. | One per distinct type argument, transitively. |
| Representation of values | Uniform — typically a pointer, so primitives are boxed. | Native — the type’s own layout, inline. |
| Calls inside the generic | Indirect, through a dictionary or an interface table. | Direct, and therefore inlinable. |
| Binary size | Flat as instantiations grow. | Grows with the number of instantiations; a known cause of large binaries. |
| Compile time | Checked once. | Codegen repeated per instantiation, and it is often the dominant build cost. |
| At run time | The type argument is gone, so it cannot be inspected. | There is no type argument left — the code was specialized for it. |