Optimizing Go Applications in Containers
· β 3 min read
1. Memory Alignment Arrange the fields inside a struct from largest to smallest.
This reduces memory footprint.
Install the fieldalignment tool 1 go install golang.org/x/tools/go/analysis/passes/fieldalignment/cmd/fieldalignment@latest Analyze and fix memory alignment 1 2 3 4 5 6 7 8 9 fieldalignment -fix ./... /Users/shaowenchen/Code/app/config/config.go:136:14: struct with 32 pointer bytes could be 24 /Users/shaowenchen/Code/app/config/config.