Skip to content

Commit 25cee43

Browse files
Merge pull request #723 from Mark-Simulacrum/speed-spq
Speed up self-profile-query view
2 parents 685a897 + 801edab commit 25cee43

File tree

5 files changed

+118
-24
lines changed

5 files changed

+118
-24
lines changed

database/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,7 @@ impl Index {
671671
.keys()
672672
.filter(move |path| path.0 == krate && path.1 == profile && path.2 == cache)
673673
.map(|path| path.3)
674+
.filter(|q| !q.as_str().starts_with("codegen passes ["))
674675
}
675676
}
676677

database/src/pool.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ pub trait Connection: Send + Sync {
5050
series: &[u32],
5151
cid: &[Option<ArtifactIdNumber>],
5252
) -> Vec<Vec<Option<f64>>>;
53+
async fn get_self_profile(
54+
&self,
55+
cid: ArtifactIdNumber,
56+
crate_: &str,
57+
profile: &str,
58+
cache: &str,
59+
) -> HashMap<crate::QueryLabel, QueryDatum>;
5360
async fn get_self_profile_query(
5461
&self,
5562
series: u32,

database/src/pool/postgres.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ pub struct CachedStatements {
232232
get_pstat: Statement,
233233
insert_pstat: Statement,
234234
get_self_profile_query: Statement,
235+
get_self_profile: Statement,
235236
insert_self_profile_query: Statement,
236237
select_self_query_series: Statement,
237238
insert_self_query_series: Statement,
@@ -333,6 +334,17 @@ impl PostgresConnection {
333334
)
334335
.await
335336
.unwrap(),
337+
get_self_profile: conn.prepare("
338+
select
339+
query, self_time, blocked_time, incremental_load_time, number_of_cache_hits, invocation_count
340+
from self_profile_query_series
341+
join self_profile_query on self_profile_query_series.id = self_profile_query.series
342+
where
343+
crate = $1
344+
and profile = $2
345+
and cache = $3
346+
and aid = $4
347+
").await.unwrap(),
336348
insert_self_profile_query: conn
337349
.prepare(
338350
"insert into self_profile_query(
@@ -564,6 +576,40 @@ where
564576
invocation_count: row.get::<_, i32>(4) as u32,
565577
})
566578
}
579+
async fn get_self_profile(
580+
&self,
581+
cid: ArtifactIdNumber,
582+
crate_: &str,
583+
profile: &str,
584+
cache: &str,
585+
) -> HashMap<crate::QueryLabel, crate::QueryDatum> {
586+
let rows = self
587+
.conn()
588+
.query(
589+
&self.statements().get_self_profile,
590+
&[&crate_, &profile, &cache, &(cid.0 as i16)],
591+
)
592+
.await
593+
.unwrap();
594+
595+
rows.into_iter()
596+
.map(|r| {
597+
let self_time: i64 = r.get(1);
598+
let blocked_time: i64 = r.get(2);
599+
let incremental_load_time: i64 = r.get(3);
600+
(
601+
r.get::<_, &str>(0).into(),
602+
crate::QueryDatum {
603+
self_time: Duration::from_nanos(self_time as u64),
604+
blocked_time: Duration::from_nanos(blocked_time as u64),
605+
incremental_load_time: Duration::from_nanos(incremental_load_time as u64),
606+
number_of_cache_hits: r.get::<_, i32>(4) as u32,
607+
invocation_count: r.get::<_, i32>(5) as u32,
608+
},
609+
)
610+
})
611+
.collect()
612+
}
567613
async fn get_error(&self, cid: crate::ArtifactIdNumber) -> HashMap<String, Option<String>> {
568614
let rows = self
569615
.conn()

database/src/pool/sqlite.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,45 @@ impl Connection for SqliteConnection {
397397
.optional()
398398
.unwrap()
399399
}
400+
async fn get_self_profile(
401+
&self,
402+
cid: ArtifactIdNumber,
403+
crate_: &str,
404+
profile: &str,
405+
cache: &str,
406+
) -> HashMap<crate::QueryLabel, crate::QueryDatum> {
407+
self.raw_ref()
408+
.prepare_cached("
409+
select
410+
query, self_time, blocked_time, incremental_load_time, number_of_cache_hits, invocation_count
411+
from self_profile_query_series
412+
join self_profile_query on self_profile_query_series.id = self_profile_query.series
413+
where
414+
crate = ?
415+
and profile = ?
416+
and cache = ?
417+
and aid = ?
418+
")
419+
.unwrap()
420+
.query_map(params![&crate_, &profile, &cache, &cid.0], |r| {
421+
let self_time: i64 = r.get(1)?;
422+
let blocked_time: i64 = r.get(2)?;
423+
let incremental_load_time: i64 = r.get(3)?;
424+
Ok((
425+
r.get::<_, String>(0)?.as_str().into(),
426+
crate::QueryDatum {
427+
self_time: Duration::from_nanos(self_time as u64),
428+
blocked_time: Duration::from_nanos(blocked_time as u64),
429+
incremental_load_time: Duration::from_nanos(incremental_load_time as u64),
430+
number_of_cache_hits: r.get::<_, i32>(4)? as u32,
431+
invocation_count: r.get::<_, i32>(5)? as u32,
432+
},
433+
))
434+
})
435+
.unwrap()
436+
.collect::<Result<_, _>>()
437+
.unwrap()
438+
}
400439
async fn get_error(&self, cid: crate::ArtifactIdNumber) -> HashMap<String, Option<String>> {
401440
self.raw_ref()
402441
.prepare_cached(

site/src/selector.rs

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -665,30 +665,31 @@ impl SelfProfile {
665665
.collect::<Vec<_>>();
666666
for cid in cids.iter() {
667667
let mut queries = Vec::new();
668-
for label in labels.iter() {
669-
let query = crate::db::DbLabel::SelfProfileQuery {
670-
krate,
671-
profile,
672-
cache,
673-
query: *label,
674-
};
675-
if let Some(qd) = idx
676-
.get::<crate::db::QueryDatum>(tx.conn(), &query, cid)
677-
.await
678-
{
679-
queries.push(QueryData {
680-
label: *label,
681-
self_time: qd.self_time.as_nanos().try_into().unwrap(),
682-
number_of_cache_hits: qd.number_of_cache_hits,
683-
invocation_count: qd.invocation_count,
684-
blocked_time: qd.blocked_time.as_nanos().try_into().unwrap(),
685-
incremental_load_time: qd
686-
.incremental_load_time
687-
.as_nanos()
688-
.try_into()
689-
.unwrap(),
690-
});
691-
}
668+
log::trace!("Fetching {} self-profile-query series", labels.len());
669+
let conn = tx.conn();
670+
let cid_id = if let Some(c) = cid.lookup(&idx) {
671+
c
672+
} else {
673+
res.push(None);
674+
continue;
675+
};
676+
let cid_data = conn
677+
.get_self_profile(
678+
cid_id,
679+
krate.as_str(),
680+
&profile.to_string(),
681+
&cache.to_string(),
682+
)
683+
.await;
684+
for (label, qd) in cid_data {
685+
queries.push(QueryData {
686+
label,
687+
self_time: qd.self_time.as_nanos().try_into().unwrap(),
688+
number_of_cache_hits: qd.number_of_cache_hits,
689+
invocation_count: qd.invocation_count,
690+
blocked_time: qd.blocked_time.as_nanos().try_into().unwrap(),
691+
incremental_load_time: qd.incremental_load_time.as_nanos().try_into().unwrap(),
692+
});
692693
}
693694
if queries.is_empty() {
694695
res.push(None);

0 commit comments

Comments
 (0)