ITADN

Suggest Struct Field reordering

#17244ClosedAaronDsouza54 创建于 2026-06-14
A-lint
A
AaronDsouza54commented
### What it does This lint should suggest more memory efficient struct field ordering so that a developer can explicitly follow it and improve memory performance. ### Advantage - Struct padding can introduce unnecessary memory padding which increases memory usage which is usually fine for small systems but can slowly start affecting memory performance for large arrays. Adding this lint can explicitly show developers a better way to reorder code. - Promotes writing performant code for databases, compilers, and game engines for less experiences systems programmers like myself. - Promotes better cache locality - Very low risk optimization since no code changes will be needed. ### Drawbacks - A potential drawback could be that usually logical ordering of fields is given a higher priority than performance based ordering. ### Example ```rust struct ExampleOfBadCode { a: u8, b: u64, c: u8, } // This is about 24 bytes after struct padding ``` Could be written as: ```rust struct ExampleOfBetterCode { b: u64, a: u8, c: u8, } // 16 bytes after struct padding which is 33% less ``` ### Comparison with existing lints _No response_ ### Additional Context _No response_
关闭于 2026-06-14 3 条评论