Skip to content

Commit a8ea6b7

Browse files
committed
Experiment: disable the niche optimization for most enums
(Only keep it for every small enum to avoid cases where the size is doubling) Trying to use the niche optimisation more often lead to performence regression It would be interresting to know what would be the performence improvement by not having the niche optimization.
1 parent c6bebc1 commit a8ea6b7

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

compiler/rustc_data_structures/src/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#[macro_export]
33
macro_rules! static_assert_size {
44
($ty:ty, $size:expr) => {
5-
const _: [(); $size] = [(); ::std::mem::size_of::<$ty>()];
5+
// const _: [(); $size] = [(); ::std::mem::size_of::<$ty>()];
66
};
77
}
88

compiler/rustc_middle/src/ty/layout.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,9 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
12161216
};
12171217

12181218
let best_layout = match (tagged_layout, niche_filling_layout) {
1219-
(tagged_layout, Some(niche_filling_layout)) => {
1219+
(tagged_layout, Some(niche_filling_layout))
1220+
if niche_filling_layout.size <= Size::from_bytes(16) =>
1221+
{
12201222
// Pick the smaller layout; otherwise,
12211223
// pick the layout with the larger niche; otherwise,
12221224
// pick tagged as it has simpler codegen.
@@ -1226,7 +1228,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
12261228
(layout.size, cmp::Reverse(niche_size))
12271229
})
12281230
}
1229-
(tagged_layout, None) => tagged_layout,
1231+
(tagged_layout, _) => tagged_layout,
12301232
};
12311233

12321234
tcx.intern_layout(best_layout)

0 commit comments

Comments
 (0)