Inspectopedia 2026.2 Help

Struct field alignment

Reports Go struct types where reordering fields would reduce memory usage by minimizing padding.

The Go compiler inserts padding bytes between struct fields to satisfy alignment requirements. When fields are ordered suboptimally, this padding can waste significant memory — especially in structs allocated in large numbers (slices, maps, caches).

Reordering fields from largest to smallest alignment eliminates unnecessary padding and reduces the struct's memory footprint. Use the Update struct layout quick-fix to apply the optimal field order automatically.

Locating this inspection

By ID

Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.

GoStructLayout
Via Settings dialog

Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.

Settings or Preferences | Editor | Inspections | Go | General

Example:

type Config struct { Active bool // 1 byte + 7 bytes padding Value int64 // 8 bytes Flag bool // 1 byte + 7 bytes padding } // Total: 24 bytes, 14 bytes wasted

Here, bool fields between int64 fields cause 7 bytes of padding each due to alignment requirements. The struct wastes 14 out of 24 bytes (58%).

After the quick-fix is applied:

type Config struct { Value int64 // 8 bytes Active bool // 1 byte Flag bool // 1 byte + 6 bytes padding } // Total: 16 bytes, saved 8 bytes

By placing the largest field first, both bool fields share a single padding block at the end. The struct size drops from 24 to 16 bytes — a 33% reduction.

Inspection ID: GoStructLayout

Inspection options

Here you can find the description of settings available for the Struct field alignment inspection, and the reference of their default values.

Only highlight if padding exceeds (bytes)

Option ID:

threshold

Default value:

4

Suppressing Inspection

You can suppress this inspection by placing the following comment marker before the code fragment where you no longer want messages from this inspection to appear:

//noinspection GoStructLayout

More detailed instructions as well as other ways and options that you have can be found in the product documentation:

Inspection Details

By default bundled with:

GoLand 2026.2, Qodana for Go 2026.2,

Last modified: 30 June 2026