Go 1.27 introduces a performance enhancement for memory allocations of objects smaller than 80 bytes. This optimization can result in these specific allocations being 20-30% faster. For programs that frequently perform many small allocations, this change can lead to an overall performance improvement of up to 1%.
The Go runtime achieves this speedup by adding specialized functions tailored for specific allocation sizes. These functions can make assumptions about the allocation characteristics, allowing for more efficient and optimized memory management. The compiler inserts calls to a wrapper function, newobject, which then passes the object's size and pointer status to the runtime's mallocgc function.
The allocator organizes memory into 'size classes,' which are ranges of sizes. For example, size class 3 covers objects between 17 and 24 bytes. The allocator provides a block of memory from a list of free objects sized to the maximum of that class. Additionally, allocations are categorized by whether they contain pointers, leading to separate free lists (spans) for bookkeeping related to garbage collection. The combination of size class and pointer presence forms a 'span class'.
The implementation of size-specialized malloc involves generating a unique mallocgc variant for every span class. For instance, a function like mallocgcSmallNoScanSC3 is created for pointer-free objects in size class 3 (17-24 bytes). This specialization allows the allocator to bypass general-purpose logic and execute highly optimized code paths for common small allocation patterns.
✨ This summary was generated by AI from the outlets' reporting listed below. It is not independently verified and may contain errors — check the original sources. How BrevFeed works →
One email each morning: the day's tech stories, clustered across outlets and summarized. No account needed.
One email a day. Unsubscribe in one click, any time.
Spend a few minutes, get the whole day. Every topic's top stories in one hands-free rundown — listen, watch, or read the transcript.
▶ Play today's briefNew every morning, and the back catalogue is archived by date.
Go 1.27 includes optimizations for memory allocations under 80 bytes, making these allocations up to 30% faster. This improvement can increase the speed of allocation-heavy Go programs by up to 1% by using specialized functions for different allocation sizes and pointer statuses.