Can you help me understand "fieldalignment: struct with 40 pointer bytes could be 8" ? #2298
-
Hello, For privacy reasons, I've renamed the fields of the struct with "anonymized" names type MyStruct struct {
FirstID int64
SecondID int64
ThirdID int64
FourthID int64
Name string
} When I run the golang-ci on this piece of code on travis, I get the following answer : I don't see what's wrong with the order of the fields. Travis is running Thank you for your kind help. |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 6 replies
-
Check this one 😉 https://itnext.io/structure-size-optimization-in-golang-alignment-padding-more-effective-memory-layout-linters-fffdcba27c61 |
Beta Was this translation helpful? Give feedback.
-
For some reason I don't understand, moving the strings at the beginning of the struct rather than at the end (despite having no effect on the size of the struct itself, see link in cristaloleg's answer) did the trick. |
Beta Was this translation helpful? Give feedback.
-
I think @1pkg found the answer here: 1pkg/gopium#24. |
Beta Was this translation helpful? Give feedback.
-
There is a tool to detect and fix this.
|
Beta Was this translation helpful? Give feedback.
-
TLDR: All pointers should come first to optimize GC. |
Beta Was this translation helpful? Give feedback.
-
Check out this comment |
Beta Was this translation helpful? Give feedback.
-
Here is a pretty good explanation with a nice visual: https://medium.com/@sebassegros/golang-dealing-with-maligned-structs-9b77bacf4b97 The interesting bit:
|
Beta Was this translation helpful? Give feedback.
For some reason I don't understand, moving the strings at the beginning of the struct rather than at the end (despite having no effect on the size of the struct itself, see link in cristaloleg's answer) did the trick.