Compiler-driven struct field reordering, as seen in Rust and Zig, is argued to be more harmful than helpful. While sorting fields from largest to smallest minimizes struct size and can improve cache line utilization, the compiler cannot know which fields are accessed together — only the programmer can. A concrete example shows a 'correctly sorted' struct running 20% slower because logically related fields end up far apart in memory. Additional problems include breaking binary compatibility with file formats and C FFI interop. The author concludes that the savings are often small, opt-out mechanisms are error-prone, and programmers who truly care about performance won't be satisfied with a heuristic default.

8m watch time
5.8K Impressions