From a8ea6b7e15824f725f3f38c43935d83db86a536f Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Sun, 11 Oct 2020 13:28:51 +0200 Subject: [PATCH] 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. --- compiler/rustc_data_structures/src/macros.rs | 2 +- compiler/rustc_middle/src/ty/layout.rs | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_data_structures/src/macros.rs b/compiler/rustc_data_structures/src/macros.rs index b918ed9458cda..8be0a0a654f5e 100644 --- a/compiler/rustc_data_structures/src/macros.rs +++ b/compiler/rustc_data_structures/src/macros.rs @@ -2,7 +2,7 @@ #[macro_export] macro_rules! static_assert_size { ($ty:ty, $size:expr) => { - const _: [(); $size] = [(); ::std::mem::size_of::<$ty>()]; + // const _: [(); $size] = [(); ::std::mem::size_of::<$ty>()]; }; } diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index f6f71d002a88a..a83ce181cf2e9 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -1216,7 +1216,9 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { }; let best_layout = match (tagged_layout, niche_filling_layout) { - (tagged_layout, Some(niche_filling_layout)) => { + (tagged_layout, Some(niche_filling_layout)) + if niche_filling_layout.size <= Size::from_bytes(16) => + { // Pick the smaller layout; otherwise, // pick the layout with the larger niche; otherwise, // pick tagged as it has simpler codegen. @@ -1226,7 +1228,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { (layout.size, cmp::Reverse(niche_size)) }) } - (tagged_layout, None) => tagged_layout, + (tagged_layout, _) => tagged_layout, }; tcx.intern_layout(best_layout)