Closed lukaszraczylo closed 1 year ago
Of course, more information - https://en.wikipedia.org/wiki/Data_structure_alignment
As an example - before the alignment After alignment
Well, how much memory is saved by reordering the fields then? Please measure this. And the build still fails.
serialization/model.pb.go:311:32: struct of size 80 could be 72
serialization/model.pb.go:387:27: struct with 56 pointer bytes could be 40
detector.go:90:23: struct with 112 pointer bytes could be 80
model.go:25:32: struct with 24 pointer bytes could be 16
detector_test.go:222:17: struct with 16 pointer bytes could be 8
detector_test.go:289:17: struct with 32 pointer bytes could be 16
detector_test.go:470:17: struct with 48 pointer bytes could be 40
detector_test.go:510:17: struct with 72 pointer bytes could be 56
model_test.go:201:14: struct with 32 pointer bytes could be 24
model_test.go:229:14: struct with 16 pointer bytes could be 8
Via https://pkg.go.dev/golang.org/x/tools/go/analysis/passes/fieldalignment You're welcome.
Hi @lukaszraczylo, can you please explain how the reordering of the struct fields would decrease the memory footprint? Apart from that, the build fails because you have not reordered all occurrences of the fields.