gocql icon indicating copy to clipboard operation
gocql copied to clipboard

Suboptimal struct alignment

Open mmatczuk opened this issue 8 years ago • 5 comments

What version of Gocql are you using?

2e9f2912

I suggest fixing the struct alignment to reduce memory footprint. I think that it's important to get Conn, Session, Query fixed.

github.com/gocql/gocql: cluster.go:30:6: struct ClusterConfig could have size 296 (currently 320)
github.com/gocql/gocql: conn.go:125:6: struct Conn could have size 208 (currently 224)
github.com/gocql/gocql: errors.go:102:6: struct RequestErrReadFailure could have size 120 (currently 128)
github.com/gocql/gocql: errors.go:83:6: struct RequestErrReadTimeout could have size 112 (currently 120)
github.com/gocql/gocql: frame.go:1360:6: struct queryParams could have size 72 (currently 80)
github.com/gocql/gocql: frame.go:1530:6: struct writeBatchFrame could have size 40 (currently 48)
github.com/gocql/gocql: frame.go:329:6: struct frameHeader could have size 56 (currently 64)
github.com/gocql/gocql: host_source.go:99:6: struct HostInfo could have size 344 (currently 352)
github.com/gocql/gocql: policies.go:227:6: struct selectedHost could have size 344 (currently 352)
github.com/gocql/gocql: session.go:1337:6: struct nextIter could have size 296 (currently 304)
github.com/gocql/gocql: session.go:1357:6: struct Batch could have size 120 (currently 136)
github.com/gocql/gocql: session.go:33:6: struct Session could have size 696 (currently 720)
github.com/gocql/gocql: session.go:655:6: struct Query could have size 240 (currently 264)

mmatczuk avatar Mar 19 '18 13:03 mmatczuk

Im not too concerned about things we dont have lots of namely session and cluster.

Zariel avatar Apr 07 '18 11:04 Zariel

frameHeader is used a lot, Query also looks like good candidate to fix.

mmatczuk avatar Apr 09 '18 10:04 mmatczuk

@mmatczuk - what tool are you using in order to generate these struct alignment reports? That seems handy and I wasn’t aware anything like that existed.

deckarep avatar Oct 21 '18 02:10 deckarep

@deckarep I was using maligned.

mmatczuk avatar Oct 23 '18 12:10 mmatczuk

Currently, the maligned is deprecated, but fieldalignment analyzer can be used instead. Reducing struct size, improving cache efficiency, and minimizing memory usage in large collections sound good, but it's not high priority. @joao-r-reis, maybe we should add it to v2.x scope, wdyt?

OleksiienkoMykyta avatar Mar 27 '25 08:03 OleksiienkoMykyta