You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The goal is to divorce the order of fields in source code from the order of struct fields, then optimize structs by always ordering fields from least to most aligned in memory layout. 1
Proposal
typeUnoptimizedstruct {
aint8bint16cint8...
}
During compile time optimization phase, Go should try to optimize reordering for all structs and their fields.
golang.org/x/tools already have a linter called fieldalignment that detects structs that would use less memory if their fields were sorted.
Backward Compatibility
I don't have much technical detail about the compiler to cover this section. So waiting your thoughts!
New go:noreorder compiler directive
The //go:noreorder directive must be followed by a type struct declaration. It specifies that auto reordering should not be applied, overriding the compiler's usual optimization rules.
P.S:I couldn't find neither a similar proposal her nor discussions; so feel free to close and drop some references if this is duplicate or have discussed before.
This is not a duplicate of #36606 as that issue does not propose any reordering of fields. (However, I have seen this issue discussed before and would be surprised if this is not a duplicate of a much earlier issue but I can't seem to find one.)
Context
The goal is to divorce the order of fields in source code from the order of struct fields, then optimize structs by always ordering fields from least to most aligned in memory layout. 1
Proposal
During compile time optimization phase, Go should try to optimize reordering for all structs and their fields.
6
,4
, respectively.golang.org/x/tools already have a linter called fieldalignment that detects structs that would use less memory if their fields were sorted.
Backward Compatibility
I don't have much technical detail about the compiler to cover this section. So waiting your thoughts!
go:noreorder
compiler directiveSimilar Works
P.S: I couldn't find neither a similar proposal her nor discussions; so feel free to close and drop some references if this is duplicate or have discussed before.
Footnotes
https://go101.org/article/memory-layout.html ↩
The text was updated successfully, but these errors were encountered: