betteralign - structs field alignment static analyzer for Go

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

Our great sponsors
  • WorkOS - The modern identity platform for B2B SaaS
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • SaaSHub - Software Alternatives and Reviews
  • 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.

  • WorkOS

    The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.

    WorkOS logo
  • 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