TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Structslop: Struct Alignment Analyzer for Go

10 点作者 Jonas_ba超过 4 年前

5 条评论

wahern超过 4 年前
&gt; That said, some structs may have a smaller size, but for efficiency, the Go runtime will allocate them in the same size class, then those structs are not considered sloppy:<p>It&#x27;s not for efficiency, per se. As in C, to support arrays of structs all structs are padded so their size is a multiple of the strictest (largest) alignment of any of its members. If the example struct described above were 24 bytes instead of 32, then the second element of an <i>array</i> of those structs wouldn&#x27;t be properly aligned for any of its uint64 or pointer members. On architectures that require aligned loads and stores that&#x27;s not an efficiency optimization, but required for correctness.
anitil超过 4 年前
Looking at this from a performance point of view, I think this could be useful with the addition of some tracing capability.<p>What I mean is, reducing the size of a barely-used struct isn&#x27;t worth the effort, but reduction of a key struct in a critical region, or a large bloated array of structs could be very useful.<p>So some measure of: possible reduction (which structslop provides), &#x27;hotness&#x27;, and total memory usage, would make this a killer feature.<p>From my bare-metal days we used to manually rearrange structs or use them packed, but it&#x27;d be great to have a tool that could attach to your codebase and do that analysis for you.
GauntletWizard超过 4 年前
This is fascinating... but I do believe there’s a reason that those fields are not re-arranged by the go compiler already, which is to preserve C ABI Compatibility. I doubt that’s worth it in most cases, though. Does it still preserve them in “pure” mode?
评论 #25042320 未加载
Jonas_ba超过 4 年前
Blog post: <a href="https:&#x2F;&#x2F;medium.com&#x2F;orijtech-developers&#x2F;efficient-struct-packing-guided-pass-for-go-92255872ec72" rel="nofollow">https:&#x2F;&#x2F;medium.com&#x2F;orijtech-developers&#x2F;efficient-struct-pack...</a>
mhh__超过 4 年前
You could do this whole analysis (and changes if you wanted to) at compile time in D. Not that you should (they&#x27;re aligned like they are for a reason)