The Go BlogMichael Matloob7 min readintermediate
Size-Specialized Memory Allocation
Summary
Go 1.27 adds a set of span‑class‑specific malloc functions for allocations ≤ 80 bytes. By generating a tiny, constant‑size allocator per span class the runtime can inline size‑dependent work (e.g. zero‑clear) and skip span‑class lookup, yielding 20‑30 % faster small allocations and ~1 % overall speed‑up for allocation‑heavy programs. The implementation is generated automatically via an AST inline…
- Specialized malloc functions are generated for each span class (size class + pointer‑ness) up to 80 bytes.
- Constant‑size clears let the compiler emit inline zeroing instead of calling `memclrNoHeapPointers`.
- The compiler can emit direct calls to the specialized allocator when the span class is known at compile time, otherwise it falls back to a dynamic dispatch.
- Code‑size and icache pressure were the primary limits; the team stopped at 80 bytes after benchmarking.
Small allocations dominate Go workloads (e.g. interface values, strings, slice headers). Even a modest per‑allocation speed‑up translates into measurable end‑to‑end gains for services that allocate heavily, without requiring any code changes from users.
6/10


