betteralign - structs field alignment static analyzer for Go

This page summarizes the projects mentioned and recommended in the original post on reddit.com/r/golang

Our great sponsors
  • InfluxDB - Access the most powerful time series database as a service
  • CodiumAI - TestGPT | Generating meaningful tests for busy devs
  • ONLYOFFICE ONLYOFFICE Docs — document collaboration in your environment
  • SonarLint - Clean code begins in your IDE with SonarLint
  • betteralign

    Make your Go programs use less memory (maybe)

    I've written betteralign, a tool to detect structs that would use less memory if their fields were sorted and optionally sort such fields. Truth be told, there are a few projects already doing this task perfectly such as fieldalignment, maligned and structslop so you might wonder why should you bother with checking this tool at all. This is a fork of an official Go fieldalignment tool and vast majority of the alignment code has remained the same. There are however some notable changes:

  • go

    The Go programming language

    In case you are wondering why DST and not AST, in general sense AST does not associate comments to nodes, but it holds fixed offsets. Original fieldalignment tool just erases all struct/field/floating comments due to this issue and while there is a CL with a possible fix, it's still a work in progress as of this time.

  • InfluxDB

    Access the most powerful time series database as a service. Ingest, store, & analyze all types of time series data in a fully-managed, purpose-built database. Keep data forever with low-cost storage and superior data compression.

  • maligned

    Tool to detect Go structs that would take less memory if their fields were sorted.

    I've written betteralign, a tool to detect structs that would use less memory if their fields were sorted and optionally sort such fields. Truth be told, there are a few projects already doing this task perfectly such as fieldalignment, maligned and structslop so you might wonder why should you bother with checking this tool at all. This is a fork of an official Go fieldalignment tool and vast majority of the alignment code has remained the same. There are however some notable changes:

  • structslop

    structslop is a static analyzer for Go that recommends struct field rearrangements to provide for maximum space/allocation efficiency.

    I've written betteralign, a tool to detect structs that would use less memory if their fields were sorted and optionally sort such fields. Truth be told, there are a few projects already doing this task perfectly such as fieldalignment, maligned and structslop so you might wonder why should you bother with checking this tool at all. This is a fork of an official Go fieldalignment tool and vast majority of the alignment code has remained the same. There are however some notable changes:

  • dst

    Decorated Syntax Tree - manipulate Go source with perfect fidelity.

    Retaining comments has been done with using DST (Decorated Syntax Tree) with decorating regular AST. Sadly when using DST we cannot use "fix" mode with SuggestedFixes, but we have to print whole DST to retain decorations. Leading/ending comment positioning isn't well retained in some cases and it's still a work in progress.

  • goimports

    [mirror] Go Tools (by golang)

    For more gopls settings, you can see files in this folder: https://github.com/golang/tools/tree/master/gopls/doc

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts