Struct layout
Use when the user asks about Go struct memory layout, field alignment, padding, struct size optimization, or memory efficiency of structs. Trigger on phrases "struct layout", "memory layout", "struct padding", "struct alignment", "struct size", "optimize struct", "struct memory", "field ordering", "struct optimization". Shows current field layout with sizes and offsets, then suggests optimal field ordering to minimize padding.From its SKILL.md
npx -y skills add athapong/go-checker --skill struct-layoutAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
2 things to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
2.3 KB, as published. Nobody here has run it
Analyze Go struct memory layout and suggest optimizations using structlayout.
- Run the go-tool-installer agent to verify the environment.
- If the user did not provide both package and struct name, ask:
"Which struct to analyze?
- Package path (e.g.
./internal/modelsorexample.com/pkg) - Struct name (e.g.
User,Request)"
- Package path (e.g.
- Run the struct layout script:
bash "$(ls ~/.claude/plugins/cache/athapong-go-checker/go-checker/*/scripts/struct-layout.sh 2>/dev/null | head -1)" <package> <StructName> - Show the full output: current layout then optimized layout.
- Explain the output to the user:
- Each field shows: name, type, size (bytes), offset (bytes from struct start), and any padding
- Padding bytes are wasted space caused by alignment requirements
- The optimized layout reorders fields to pack them tighter (largest alignment first)
- If optimized layout differs from current:
- Calculate total size reduction:
current_size - optimized_sizebytes saved - Tell the user: "Reordering fields as shown saves N bytes per struct instance. At scale (e.g. 1M instances), that's N MB."
- Show the suggested field declaration order as a Go struct snippet
- Calculate total size reduction:
- If no padding exists (layout already optimal), tell the user: "Struct is already optimally packed — no padding waste."
- Tell the user the report was saved to
./go-checker-reports/struct-layout-<timestamp>.txt.
Background for explanations:
- Go aligns each field to its natural alignment (bool=1, int32=4, int64=8, pointer=8 on 64-bit)
- The compiler inserts padding bytes between fields to satisfy alignment
- Reordering fields largest-to-smallest alignment typically eliminates padding
structlayout-optimizeuses a greedy algorithm: sorts fields by alignment descending, then by size descending