proposal: Add fieldalignment to generated structs #2070
switchupcb
started this conversation in
Ideas
Replies: 2 comments 3 replies
-
As you have already noticed I proposed this long ago. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Please, continue the PR. It will be analyzed and merged ASAP. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
What is fieldalignment?
Struct padding aligns fields of a structs to addresses in memory. This is done to improve performance and prevent numerous issues on a system's architecture (32-bit, 64-bit). For a simple explanation, view Golang Struct Size and Memory optimization (visual example). In Go, fieldalignment can be checked and fixed using the fieldalignment tool which is installed using
go install golang.org/x/tools/go/analysis/passes/fieldalignment/cmd/fieldalignment@latest
. Misaligned fields add more memory-usage to a program, which can effect performance in a numerous amount of ways. This proposal aims to save memory by adding fieldalignment to gqlgen.Read More
Fieldalignment in Practice: https://itnext.io/structure-size-optimization-in-golang-alignment-padding-more-effective-memory-layout-linters-fffdcba27c61
Memory Layouts: https://go101.org/article/memory-layout.html
fieldalignment in gqlgen
The following code block contains output from
fieldalignment -fix
on gqlgen structs.176 bytes saved. 20 misaligned models. You don't use these models in every request. So for each model used in 1 MILLION requests, that's...
8.8 MB saved per misaligned model.
Along with better Garbage Collection performance due to a lower amount of peaks.
Previous Mentions
#1710 (#1895)
Steps
go install golang.org/x/tools/go/analysis/passes/fieldalignment/cmd/fieldalignment@latest
: Where should this be configured from in the .yml?Beta Was this translation helpful? Give feedback.
All reactions