Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 1ea7b41

Browse files
committed
Auto merge of rust-lang#120465 - blyxyas:selfprof-is_enabled, r=<try>
[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)
2 parents fb4bca0 + 97814dd commit 1ea7b41

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

compiler/rustc_session/src/utils.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ impl Session {
99
}
1010
/// Used by `-Z self-profile`.
1111
pub fn time<R>(&self, what: &'static str, f: impl FnOnce() -> R) -> R {
12-
self.prof.verbose_generic_activity(what).run(f)
12+
if self.prof.enabled() {
13+
return self.prof.verbose_generic_activity(what).run(f)
14+
} else {
15+
return f()
16+
}
1317
}
1418
}
1519

0 commit comments

Comments
 (0)