gpad is a Go CLI Tool that automatically reorders struct fileds across your codebase to optimize memory layout and reduce padding. It helps improve memory efficiency in Go programs by analyzing structs and rearranging fields for better alignment.
Install gpad using go install:
go install github.com/devasherr/gpad@v0.1.2After installation, run gpad from the root of your Go project:
gpadThats it, all structs in the codebase have been sorted!!
- You can also specify a custom directory to start from using the -path flag:
gpad -path "/internal/models"This will only process structs within the specified directory and its subdirectories
- If you want more details you can run the tool in verbose mode:
gpad -path "/internal/models" -v| Metric | Value |
|---|---|
| Time Taken: | 6.370862ms |
| Initial Allocation: | 128 bytes |
| Current Allocation: | 112 bytes |
| Saved: | 16 bytes (12.50%) |