{"repo":"dkorunic/betteralign","free":true,"listed":false,"github":"https://github.com/dkorunic/betteralign","clone":"git clone https://github.com/dkorunic/betteralign.git","description":"Detect and fix struct field alignment to reduce memory usage in Go programs","language":"Go","stars":1076,"topics":["alignment","analyzer","golang","memory","garbage-collector"],"license":"BSD-3-Clause","category":"dev-tools","readme_excerpt":"betteralign About betteralign is a tool that detects structs that would use less memory if their fields were reordered, and optionally rewrites them. It is a fork of the official Go fieldalignment tool, with the bulk of the alignment logic unchanged. Its notable differences group into a few themes: Why this exists - preserves comments (field comments, doc comments, and floating comments) — the original fieldalignment erases them on rewrite. Safety and robustness - detects positional composite literals ( T{1, 2, 3} rather than T{a: 1, b: 2, c: 3} ) anywhere in the package and reports the would-be saving without rewriting the struct — reordering its fields would silently re-map the literal's elements at the next build, - analyzes only named struct types declared with type T struct { ... } ; anonymous structs (nested struct-typed fields, struct literals, var x struct{...} declarations) are skipped, so it never rewrites the riskier unnamed shapes, - when -apply rewrites a struct, fields declared with multiple names ( A, B int ) are kept together as a single grouped declaration and moved as a unit — the byte-span reorder never splits them, - performs atomic file writes to prevent corruption or data loss on rewrite (not on Windows), - uses a stable sort for field ordering, so fields of equal sort rank preserve their original relative order; upstream's sort.Slice is unstable and may permute equal-ranked fields differently between runs, - fixes a crash on packages with generic struct","default_branch":null,"files":null,"tree":[],"storefront":"/r/dkorunic","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/dkorunic/betteralign/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}