See the padding Go inserts. Reorder in one click.
Inline annotations, byte map, pack score, cache lines, amd64 / arm64 / 386
VS Code extension that shows how a Go struct sits in memory: the byte offset of each field, the padding the compiler adds between them, and how much of the struct is wasted space. When a reorder would shrink it, one click rewrites the field order for you (comments and tags kept).
type Sparse struct {
Active bool // 1B + 7B padding
ID uint64
Tag uint8 // 1B + 7B padding
Name string
}
// 40B, pack 65%, 14B wastedOpen the file, annotations appear, click Optimize Layout:
Sparse 40B pack 65% pad 14B
0000 A.......BBBBBBBB
0010 C.......DDDDDDDD
0020 DDDDDDDD
legend: A=Active B=ID C=Tag D=Name .=padding
After reorder: 32B, pack 85%, saved 8 bytes. Same fields, less air.
- Spot padding without running
unsafe.Sizeofor reading the Go ABI by hand - Cut struct size on hot types (API responses, events, DB models)
- Paste the ASCII map into a PR so reviewers see the waste
- Learn how alignment actually works
In VS Code, Ctrl+P then:
ext install RhinoSoftware.go-memory-visualizer
Or from the Marketplace or Open VSX.
From source:
git clone https://github.com/1rhino2/go-memory-visualizer.git
cd go-memory-visualizer
npm install
npm run compile
# open in VS Code, press F5 for the Extension Development HostCommand Palette (Ctrl+Shift+P):
| Command | What it does |
|---|---|
Go: Show Memory Layout |
Memory breakdown for every struct in the file |
Go: Show Visual Memory Map |
Byte grid + ASCII map for the struct at the cursor |
Go: Optimize Struct Memory Layout |
Reorder fields to cut padding |
Go: Toggle Architecture |
Switch amd64 / arm64 / 386 |
Go: Export Memory Layout Report |
Export to JSON, Markdown, or CSV |
Go: Analyze Workspace Memory Layout |
Scan the workspace for padding and cache-line issues |
Go: Compare Struct Layout Across Architectures |
Side-by-side amd64 / arm64 / 386 |
Optimize is also a Quick Fix (Ctrl+.) on any reorderable struct, and the
status bar shows the bytes you could save in the current file.
Settings live under goMemoryVisualizer.* (default architecture, padding warning
threshold, cache-line warnings, confirm-before-optimize, and more). Open VS Code
Settings and search "Go Memory" to see them all.
- VS Code 1.85.0 or higher
- Node.js 20+ to build from source
npm install
npm run compile
npm testSee DEVELOPMENT.md for the internals and CHANGELOG.md for version history.
MIT, see LICENSE.
