Go 1.25 and 1.26 introduce compiler optimizations that move slice allocations from the heap to the stack, reducing garbage collector pressure and improving performance. In Go 1.25, variable-sized make calls with small enough sizes are automatically backed by a 32-byte stack buffer. In Go 1.26, append-allocated slices also get a small speculative stack-allocated backing store, avoiding the startup-phase heap allocations (sizes 1, 2, 4, etc.). Additionally, for escaping slices, Go 1.26 automatically inserts a runtime.move2heap call so intermediate allocations stay on the stack and only one final heap allocation of the correct size is made. These changes reduce heap allocations and GC overhead without requiring code changes.

10m read timeFrom go.dev
Post cover image
Table of contents
Stack allocation of constant-sized slices ¶Stack allocation of variable-sized slices ¶Stack allocation of append-allocated slices ¶Stack allocation of append-allocated escaping slices ¶Wrapping up ¶Footnotes ¶

Sort: