TLDR Dev · ARTICLES & TUTORIALS

OPTIMIZATION CATALOG. HOW 4 BYTES OF PADDING MAKE ARRAY CLEARING 49% FASTER

blog.andr2i.com10 min read

Summary from the TLDR Dev newsletter

Adding 4 bytes of padding between a struct's fields in Go can improve the performance of array clearing, achieving up to a 49% increase in speed on Intel machines due to better instruction optimizations. When the array elements are misaligned, the performance suffers because the processor's optimized memory handling cannot be fully used.