Go 1.27's size-specialized memory allocation makes small allocations up to 30% faster

Go 1.27 introduces size-specialized allocation for objects of 80 bytes or fewer, boosting allocation speed by 20–30% and overall program speed by up to 1%. The runtime generates specialized mallocgc functions for each span class, enabling faster memory clearing and reduced overhead. The biggest gains hit common 16- and 24-byte sizes, like interfaces and slices. No code changes needed—just build with Go 1.27.

We spent a lot of time tuning the behavior of size specialized malloc and making sure the impact of the instruction cache effects will be minimal: we were originally planning to release size-specialized allocation in Go 1.26 but decided to wait an extra release to do extra tuning and cut down the additional code size as much as we could.
  1. pizlonator

    Super interesting!

    Fil-C's GC has basically always had size-specialized allocation and I've done some experiments with this so I have my own data.

    As the post says, there are two potential benefits:

    - Faster memory clearing when the compiler knows the size. In Fil-C, I leverage that by having LLVM emit a memset inline, so it often ends up being some SIMD crap.

    - Faster size class computation.

    Interestingly, the faster size class computation isn't really faster in practice. I implemented it and that's how the ABI works today, but I'm likely to move the size class computation into the runtime to simply the ABI, since repeated experiments show that there are no savings to be had there. It's super surprising, but the numbers don't lie.

    Anyway, cool to see other fast non-moving GCs also finding the same sweet spot as me.

    (Posted from WebKit built with Fil-C so for extra meta, I'm using the GC I describe to write this post)

More from this day

2026-09-18