# dkorunic/betteralign

Detect and fix struct field alignment to reduce memory usage in Go programs

Repository: https://github.com/dkorunic/betteralign
Canonical: https://ross.abutalabs.com/products/betteralign
Language: Go
License: BSD-3-Clause
License Family: permissive
Topics: alignment, analyzer, golang, memory, garbage-collector
Last push: 2026-08-21T10:01:24+00:00

## Health v2 (maintenance only)
Score: 96/100 (v2, computed 2026-09-03T02:20:16.233290+00:00)
- activity 98, release rhythm 98, longevity 90
- inputs: {"age_days": 1267, "days_push": 12, "days_rel": 13, "gap_med": 18, "n_releases_24m": 32}
- flags: none
- formula: round(0.45*activity + 0.35*rhythm + 0.20*longevity); archived -> min(score, 10)

## Adoption (not part of the score)
Stars 1078, forks 22 (observed 2026-08-28T04:03:29.878070+00:00)

## What it is
betteralign is a Go static analysis tool that detects structs whose fields could be reordered to reduce memory usage, and can optionally rewrite them safely. It is a fork of the official fieldalignment analyzer with improvements like comment preservation, atomic writes, and safer skip/ignore controls.

## Use cases
- reduce memory usage of Go structs by reordering fields
- find structs with suboptimal field alignment in a Go codebase
- automatically fix struct field ordering without losing comments
- detect positional composite literals that would break if fields are reordered
- run fieldalignment analysis in CI with opt-in or opt-out annotations

## When to choose
- you want memory savings from struct field reordering in Go
- you need comment-preserving rewrites that the upstream fieldalignment tool lacks
- you have generic structs or positional literals that crash or break upstream tooling

## When to avoid
- your project is not written in Go
- you only care about anonymous structs, which are deliberately skipped
- you need atomic rewrite guarantees on Windows

## Facets
- artifact type: cli-tool
- maturity: active
- function: linter, formatter, developer-tools
- domain: developer-tools, performance, programming-languages
- platform: go, cli, windows
- tags: struct-alignment, memory-optimization, static-analysis, code-rewriting, golang-analyzer, linux, macos

## Member repositories
- dkorunic/betteralign (main) score 96

## Provenance
- Observed fields: from GitHub, fetched 2026-08-28T04:03:29.878070+00:00.
- Health v2: computed from the inputs above; adoption is never an input.
- Inferred fields (summary, facets, guidance): AI-extracted, prompt v1, taxonomy v1, on 2026-08-30T06:53:08.863557+00:00, confidence not recorded.
  - readme: https://github.com/dkorunic/betteralign (fetched 2026-08-28T04:03:29.878070+00:00, sha 5e0794314b32)
- Data as of 2026-08-30T08:39:29.467469+00:00.
