Skip to content

Commit 4ce1ce1

Browse files
authored
Rollup merge of #89784 - Mark-Simulacrum:delete-cache-hit-tracking, r=petrochenkov
Remove built-in query cache_hit tracking This was already only enabled in debug_assertions builds. Generally, it seems like most use cases that would use this could also use the -Zself-profile flag which also tracks cache hits (in all builds), and so the extra cfg's and such are not really necessary. This is largely just a small cleanup though, which primarily is intended to make other changes easier by avoiding the need to deal with this field.
2 parents b55a3c5 + 1273738 commit 4ce1ce1

File tree

2 files changed

+1
-49
lines changed

2 files changed

+1
-49
lines changed

compiler/rustc_query_impl/src/stats.rs

-27
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ use rustc_query_system::query::{QueryCache, QueryCacheStore};
55

66
use std::any::type_name;
77
use std::mem;
8-
#[cfg(debug_assertions)]
9-
use std::sync::atomic::Ordering;
108

119
trait KeyStats {
1210
fn key_stats(&self, stats: &mut QueryStats);
@@ -27,7 +25,6 @@ impl KeyStats for DefId {
2725
#[derive(Clone)]
2826
struct QueryStats {
2927
name: &'static str,
30-
cache_hits: usize,
3128
key_size: usize,
3229
key_type: &'static str,
3330
value_size: usize,
@@ -42,10 +39,6 @@ where
4239
{
4340
let mut stats = QueryStats {
4441
name,
45-
#[cfg(debug_assertions)]
46-
cache_hits: map.cache_hits.load(Ordering::Relaxed),
47-
#[cfg(not(debug_assertions))]
48-
cache_hits: 0,
4942
key_size: mem::size_of::<C::Key>(),
5043
key_type: type_name::<C::Key>(),
5144
value_size: mem::size_of::<C::Value>(),
@@ -63,12 +56,6 @@ where
6356
pub fn print_stats(tcx: TyCtxt<'_>) {
6457
let queries = query_stats(tcx);
6558

66-
if cfg!(debug_assertions) {
67-
let hits: usize = queries.iter().map(|s| s.cache_hits).sum();
68-
let results: usize = queries.iter().map(|s| s.entry_count).sum();
69-
eprintln!("\nQuery cache hit rate: {}", hits as f64 / (hits + results) as f64);
70-
}
71-
7259
let mut query_key_sizes = queries.clone();
7360
query_key_sizes.sort_by_key(|q| q.key_size);
7461
eprintln!("\nLarge query keys:");
@@ -83,20 +70,6 @@ pub fn print_stats(tcx: TyCtxt<'_>) {
8370
eprintln!(" {} - {} x {} - {}", q.name, q.value_size, q.entry_count, q.value_type);
8471
}
8572

86-
if cfg!(debug_assertions) {
87-
let mut query_cache_hits = queries.clone();
88-
query_cache_hits.sort_by_key(|q| q.cache_hits);
89-
eprintln!("\nQuery cache hits:");
90-
for q in query_cache_hits.iter().rev() {
91-
eprintln!(
92-
" {} - {} ({}%)",
93-
q.name,
94-
q.cache_hits,
95-
q.cache_hits as f64 / (q.cache_hits + q.entry_count) as f64
96-
);
97-
}
98-
}
99-
10073
let mut query_value_count = queries.clone();
10174
query_value_count.sort_by_key(|q| q.entry_count);
10275
eprintln!("\nQuery value count:");

compiler/rustc_query_system/src/query/plumbing.rs

+1-22
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,15 @@ use std::hash::{Hash, Hasher};
2626
use std::mem;
2727
use std::num::NonZeroU32;
2828
use std::ptr;
29-
#[cfg(debug_assertions)]
30-
use std::sync::atomic::{AtomicUsize, Ordering};
3129

3230
pub struct QueryCacheStore<C: QueryCache> {
3331
cache: C,
3432
shards: Sharded<C::Sharded>,
35-
#[cfg(debug_assertions)]
36-
pub cache_hits: AtomicUsize,
3733
}
3834

3935
impl<C: QueryCache + Default> Default for QueryCacheStore<C> {
4036
fn default() -> Self {
41-
Self {
42-
cache: C::default(),
43-
shards: Default::default(),
44-
#[cfg(debug_assertions)]
45-
cache_hits: AtomicUsize::new(0),
46-
}
37+
Self { cache: C::default(), shards: Default::default() }
4738
}
4839
}
4940

@@ -377,10 +368,6 @@ where
377368
if unlikely!(tcx.profiler().enabled()) {
378369
tcx.profiler().query_cache_hit(index.into());
379370
}
380-
#[cfg(debug_assertions)]
381-
{
382-
cache.cache_hits.fetch_add(1, Ordering::Relaxed);
383-
}
384371
tcx.dep_graph().read_index(index);
385372
on_hit(value)
386373
})
@@ -429,10 +416,6 @@ where
429416
if unlikely!(tcx.dep_context().profiler().enabled()) {
430417
tcx.dep_context().profiler().query_cache_hit(index.into());
431418
}
432-
#[cfg(debug_assertions)]
433-
{
434-
cache.cache_hits.fetch_add(1, Ordering::Relaxed);
435-
}
436419
query_blocked_prof_timer.finish_with_query_invocation_id(index.into());
437420

438421
(v, Some(index))
@@ -705,10 +688,6 @@ where
705688
if unlikely!(tcx.dep_context().profiler().enabled()) {
706689
tcx.dep_context().profiler().query_cache_hit(index.into());
707690
}
708-
#[cfg(debug_assertions)]
709-
{
710-
cache.cache_hits.fetch_add(1, Ordering::Relaxed);
711-
}
712691
});
713692

714693
let lookup = match cached {

0 commit comments

Comments
 (0)