-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Tweak query code for performance #56613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c66b844
8e53ecf
9d888ea
517725c
5a6a133
f0adf5a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -159,6 +159,13 @@ impl Forest { | |
self.dep_graph.read(DepNode::new_no_params(DepKind::Krate)); | ||
&self.krate | ||
} | ||
|
||
/// This is internally in the depedency tracking system. | ||
/// Use the `krate` method to ensure your dependency on the | ||
/// crate is tracked. | ||
pub fn untracked_krate<'hir>(&'hir self) -> &'hir Crate { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a warning comment here not to use this function and that it only exists for internal use with the dep-tracking system. |
||
&self.krate | ||
} | ||
} | ||
|
||
/// Represents a mapping from Node IDs to AST elements and their parent | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,6 +131,9 @@ pub struct Session { | |
/// Used by -Z profile-queries in util::common | ||
pub profile_channel: Lock<Option<mpsc::Sender<ProfileQueriesMsg>>>, | ||
|
||
/// Used by -Z self-profile | ||
pub self_profiling_active: bool, | ||
|
||
/// Used by -Z self-profile | ||
pub self_profiling: Lock<SelfProfiler>, | ||
|
||
|
@@ -823,10 +826,17 @@ impl Session { | |
} | ||
} | ||
|
||
#[inline(never)] | ||
#[cold] | ||
fn profiler_active<F: FnOnce(&mut SelfProfiler) -> ()>(&self, f: F) { | ||
let mut profiler = self.self_profiling.borrow_mut(); | ||
f(&mut profiler); | ||
} | ||
|
||
#[inline(always)] | ||
pub fn profiler<F: FnOnce(&mut SelfProfiler) -> ()>(&self, f: F) { | ||
if self.opts.debugging_opts.self_profile || self.opts.debugging_opts.profile_json { | ||
let mut profiler = self.self_profiling.borrow_mut(); | ||
f(&mut profiler); | ||
if unlikely!(self.self_profiling_active) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LLVM already assigns reduced branch weights to branches postdominated by calls to cold functions, so I wouldn't expect this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did find a case where it didn't though, so I used There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd really like to have PGO for the Rust compiler at some point |
||
self.profiler_active(f) | ||
} | ||
} | ||
|
||
|
@@ -1145,6 +1155,9 @@ pub fn build_session_( | |
CguReuseTracker::new_disabled() | ||
}; | ||
|
||
let self_profiling_active = sopts.debugging_opts.self_profile || | ||
sopts.debugging_opts.profile_json; | ||
|
||
let sess = Session { | ||
target: target_cfg, | ||
host, | ||
|
@@ -1177,6 +1190,7 @@ pub fn build_session_( | |
imported_macro_spans: OneThread::new(RefCell::new(FxHashMap::default())), | ||
incr_comp_session: OneThread::new(RefCell::new(IncrCompSession::NotInitialized)), | ||
cgu_reuse_tracker, | ||
self_profiling_active, | ||
self_profiling: Lock::new(SelfProfiler::new()), | ||
profile_channel: Lock::new(None), | ||
perf_stats: PerfStats { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can turn the assertion below into a
debug_assertion
.