Memory Optimization through Structure Packaging
summary
Shows concrete results from Go: reordering fields cuts struct size from 128 vs 72 bytes, moves objects into smaller mspan classes (examples: 128, 80, 144 bytes), and yields a benchmarked speedup of ~43% runtime on the demo that creates and iterates slices of those structs. Explains allocator size classes, that a 1‑byte change can force a jump to a larger mspan and drastically drop density (fewer objects per page), and reports real‑world memory wins of about 5–40% in an observability library.
AI-written summary · about
chapters (10)
- 0:00Introduction
- 1:03Struct padding basics
- 2:52Alignment rules
- 5:02Reordering struct fields
- 6:06Benchmarking memory layout
- 7:50Key takeaways
- 8:32Mspan size classes
- 10:19Struct size impact
- 11:51Small optimizations matter
- 12:53Trade-offs of reordering
related talks
40mGolang memory footprint
19mHeap Optimization for Go Systems
21mGo Right Ahead! Simple Hacks to Cut Memory Usage by 80&
51mEvolving the Go Memory Manager's RAM and CPU Efficiency
27mOptimizing Ruby's Memory Layout
30mMemory Management in Go: The good, the bad and the ugly
32mSmall is beautiful: Techniques to minimise memory footprint
38mUnderstanding Memory Allocation in Go
