Our great sponsors
-
InfluxDB
Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
-
structslop
structslop is a static analyzer for Go that recommends struct field rearrangements to provide for maximum space/allocation efficiency.
-
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.
https://github.com/golang/go/issues/10014#issuecomment-91436...
> It seems fine to me for the spec not to guarantee anything about struct field order in memory. The spec doesn't operate at that level.
> That said, no Go compiler should probably ever reorder struct fields. That seems like it is trying to solve a 1970s problem, namely packing structs to use as little space as possible. The 2010s problem is to put related fields near each other to reduce cache misses, and (unlike the 1970s problem) there is no obvious way for the compiler to pick an optimal solution. A compiler that takes that control away from the programmer is going to be that much less useful, and people will find better compilers.
The standard way to check for these was https://github.com/mdempsky/maligned. It is now deprecated in favour of https://pkg.go.dev/golang.org/x/tools/go/analysis/passes/fie....
You can now check for these using go vet:
go install golang.org/x/tools/go/analysis/passes/fieldalignment/cmd/fieldalignment@latest
Is the situation for Rust different than as described here: https://github.com/rust-lang/rfcs/pull/208
“Currently, attributes and macros/syntax extensions are both conceptually macros: they are user-definable syntactic extensions that transform token trees to token trees.”
FWIW I definitely admit the point about Go annotations sort of cheating into this space a bit (same with struct tags which I revile…).
Go doesnt do this by default, but there are some analyzers that help you do this - https://github.com/orijtech/structslop