Skip to content

Commit

Permalink
Auto merge of rust-lang#120465 - blyxyas:selfprof-is_enabled, r=<try>
Browse files Browse the repository at this point in the history
[PERF Experiment] Only create the self-profile infra if the profiler is actually enabled (only if `-Z self-profile`)

Previously, we would use the [`Session::time`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_session/struct.Session.html#method.time) and this would just call `verbose_generic_activity(...)`, which would create an activity and all that... But all this effort would go unnoticed if the user didn't use the `-Z self-profile` feature.

So, this PR checks for the profiler before trying to profile. From my benchmarks on a server, this should be a great performance improvement (Note: I tested this with a 12-thread custom multithreaded rustc-perf clone to mimick a compiler that a user might use, the results may change by using the single-threaded rustc-perf that bors currently uses)
  • Loading branch information
bors committed Jan 29, 2024
2 parents fb4bca0 + 0939b86 commit 90adef6
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion compiler/rustc_session/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ impl Session {
}
/// Used by `-Z self-profile`.
pub fn time<R>(&self, what: &'static str, f: impl FnOnce() -> R) -> R {
self.prof.verbose_generic_activity(what).run(f)
if self.prof.enabled() {
return self.prof.verbose_generic_activity(what).run(f);
} else {
return f();
}
}
}

Expand Down

0 comments on commit 90adef6

Please sign in to comment.