Skip to content

Commit 4519845

Browse files
committed
Auto merge of #76913 - vandenheuvel:performance_debug, r=lcnr
Fixing the performance regression of #76244 Issue #74865 suggested that removing the `def_id` field from `ParamEnv` would improve performance. PR #76244 implemented this change. Generally, [results](https://perf.rust-lang.org/compare.html?start=80fc9b0ecb29050d45b17c64af004200afd3cfc2&end=5ef250dd2ad618ee339f165e9b711a1b4746887d) were as expected: an instruction count decrease of about a percent. The instruction count for the unicode crates increased by about 3%, which `@nnethercote` speculated to be caused by a quirk of inlining or codegen. As the results were generally positive, and for chalk integration, this was also a step in the right direction, the PR was r+'d regardless. However, [wall-time performance results](https://perf.rust-lang.org/compare.html?start=a055c5a1bd95e029e9b31891db63b6dc8258b472&end=7402a394471a6738a40fea7d4f1891666e5a80c5&stat=task-clock) show a much larger performance degradation: 25%, as [mentioned](#76244 (comment)) by `@Mark-Simulacrum.` This PR, for now, reverts #76244 and attempts to find out, which change caused the regression.
2 parents f47df31 + ab83d37 commit 4519845

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

compiler/rustc_infer/src/traits/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub type TraitObligation<'tcx> = Obligation<'tcx, ty::PolyTraitPredicate<'tcx>>;
5757

5858
// `PredicateObligation` is used a lot. Make sure it doesn't unintentionally get bigger.
5959
#[cfg(target_arch = "x86_64")]
60-
static_assert_size!(PredicateObligation<'_>, 32);
60+
static_assert_size!(PredicateObligation<'_>, 40);
6161

6262
pub type Obligations<'tcx, O> = Vec<Obligation<'tcx, O>>;
6363
pub type PredicateObligations<'tcx> = Vec<PredicateObligation<'tcx>>;

compiler/rustc_middle/src/ty/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1745,6 +1745,9 @@ pub struct ParamEnv<'tcx> {
17451745
///
17461746
/// Note: This is packed, use the reveal() method to access it.
17471747
packed: CopyTaggedPtr<&'tcx List<Predicate<'tcx>>, traits::Reveal, true>,
1748+
1749+
/// FIXME: This field is not used, but removing it causes a performance degradation. See #76913.
1750+
unused_field: Option<DefId>,
17481751
}
17491752

17501753
unsafe impl rustc_data_structures::tagged_ptr::Tag for traits::Reveal {
@@ -1825,7 +1828,7 @@ impl<'tcx> ParamEnv<'tcx> {
18251828
/// Construct a trait environment with the given set of predicates.
18261829
#[inline]
18271830
pub fn new(caller_bounds: &'tcx List<Predicate<'tcx>>, reveal: Reveal) -> Self {
1828-
ty::ParamEnv { packed: CopyTaggedPtr::new(caller_bounds, reveal) }
1831+
ty::ParamEnv { packed: CopyTaggedPtr::new(caller_bounds, reveal), unused_field: None }
18291832
}
18301833

18311834
pub fn with_user_facing(mut self) -> Self {

compiler/rustc_trait_selection/src/traits/fulfill.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pub struct PendingPredicateObligation<'tcx> {
8787

8888
// `PendingPredicateObligation` is used a lot. Make sure it doesn't unintentionally get bigger.
8989
#[cfg(target_arch = "x86_64")]
90-
static_assert_size!(PendingPredicateObligation<'_>, 56);
90+
static_assert_size!(PendingPredicateObligation<'_>, 64);
9191

9292
impl<'a, 'tcx> FulfillmentContext<'tcx> {
9393
/// Creates a new fulfillment context.

0 commit comments

Comments
 (0)