orijtech / structslop

structslop is a static analyzer for Go that recommends struct field rearrangements to provide for maximum space/allocation efficiency.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

detect when rearrangement changes the size class

odeke-em opened this issue · comments

Coming here from a suggestion from Josh Bleecher Snyder, we should detect when the rearrangement changes the size class of the struct.

@odeke-em do you refer to the size class that runtime use to allocate memory for struct? https://golang.org/src/runtime/mksizeclasses.go

That's right! Please see also see golang/go#42412 (comment)

Look cool!

So when size class changed, what should we report? Or we will report the actual size class instead of the struct size?

We should report all of them. Basically:

<LINENO_POS>: struct has size 112 (size class <CLASS_SIZE>), rearrange to <REARRANGEMENT> for optimal size

Also we should make sure that the optimal size suggested is an actual size class.