Skip to content

Commit c591209

Browse files
committed
Use async closures in for runtime and published artifact benchmarks
1 parent bf0224d commit c591209

File tree

2 files changed

+32
-42
lines changed

2 files changed

+32
-42
lines changed

collector/src/bin/collector.rs

Lines changed: 31 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ fn main_result() -> anyhow::Result<i32> {
766766
CargoIsolationMode::Isolated
767767
};
768768

769-
let mut rt = build_async_runtime();
769+
let rt = build_async_runtime();
770770
let mut conn = rt.block_on(pool.connection());
771771
let artifact_id = ArtifactId::Commit(Commit {
772772
sha: toolchain.id.clone(),
@@ -794,7 +794,7 @@ fn main_result() -> anyhow::Result<i32> {
794794
RuntimeBenchmarkFilter::new(local.exclude, local.include),
795795
iterations,
796796
);
797-
run_benchmarks(&mut rt, conn, shared, None, Some(config))?;
797+
rt.block_on(run_benchmarks(conn, shared, None, Some(config)))?;
798798
Ok(0)
799799
}
800800
Commands::ProfileRuntime {
@@ -923,7 +923,7 @@ fn main_result() -> anyhow::Result<i32> {
923923
r#type: CommitType::Master,
924924
});
925925

926-
let mut rt = build_async_runtime();
926+
let rt = build_async_runtime();
927927
let mut conn = rt.block_on(pool.connection());
928928
rt.block_on(purge_old_data(conn.as_mut(), &artifact_id, purge.purge));
929929

@@ -942,7 +942,7 @@ fn main_result() -> anyhow::Result<i32> {
942942
targets: vec![Target::default()],
943943
};
944944

945-
run_benchmarks(&mut rt, conn, shared, Some(config), None)?;
945+
rt.block_on(run_benchmarks(conn, shared, Some(config), None))?;
946946
Ok(0)
947947
}
948948

@@ -975,18 +975,14 @@ fn main_result() -> anyhow::Result<i32> {
975975

976976
let res = std::panic::catch_unwind(|| {
977977
let pool = database::Pool::open(&db.db);
978-
let mut rt = build_async_runtime();
978+
let rt = build_async_runtime();
979979

980980
match next {
981981
NextArtifact::Release(tag) => {
982982
let toolchain =
983983
create_toolchain_from_published_version(&tag, &target_triple)?;
984-
bench_published_artifact(
985-
rt.block_on(pool.connection()),
986-
&mut rt,
987-
toolchain,
988-
&benchmark_dirs,
989-
)
984+
let conn = rt.block_on(pool.connection());
985+
rt.block_on(bench_published_artifact(conn, toolchain, &benchmark_dirs))
990986
}
991987
NextArtifact::Commit {
992988
commit,
@@ -1077,13 +1073,12 @@ fn main_result() -> anyhow::Result<i32> {
10771073
toolchain,
10781074
};
10791075

1080-
run_benchmarks(
1081-
&mut rt,
1076+
rt.block_on(run_benchmarks(
10821077
conn,
10831078
shared,
10841079
Some(compile_config),
10851080
Some(runtime_config),
1086-
)
1081+
))
10871082
}
10881083
}
10891084
});
@@ -1102,10 +1097,10 @@ fn main_result() -> anyhow::Result<i32> {
11021097
Commands::BenchPublished { toolchain, db } => {
11031098
log_db(&db);
11041099
let pool = database::Pool::open(&db.db);
1105-
let mut rt = build_async_runtime();
1100+
let rt = build_async_runtime();
11061101
let conn = rt.block_on(pool.connection());
11071102
let toolchain = create_toolchain_from_published_version(&toolchain, &target_triple)?;
1108-
bench_published_artifact(conn, &mut rt, toolchain, &benchmark_dirs)?;
1103+
rt.block_on(bench_published_artifact(conn, toolchain, &benchmark_dirs))?;
11091104
Ok(0)
11101105
}
11111106

@@ -1657,36 +1652,27 @@ async fn init_collection(
16571652
}
16581653

16591654
/// Execute all benchmarks specified by the given configurations.
1660-
fn run_benchmarks(
1661-
rt: &mut Runtime,
1655+
async fn run_benchmarks(
16621656
mut connection: Box<dyn Connection>,
16631657
shared: SharedBenchmarkConfig,
16641658
compile: Option<CompileBenchmarkConfig>,
16651659
runtime: Option<RuntimeBenchmarkConfig>,
16661660
) -> anyhow::Result<()> {
1667-
rt.block_on(record_toolchain_sizes(
1668-
connection.as_mut(),
1669-
&shared.artifact_id,
1670-
&shared.toolchain,
1671-
));
1661+
record_toolchain_sizes(connection.as_mut(), &shared.artifact_id, &shared.toolchain).await;
16721662

1673-
let collector = rt.block_on(init_collection(
1663+
let collector = init_collection(
16741664
connection.as_mut(),
16751665
&shared,
16761666
compile.as_ref(),
16771667
runtime.as_ref(),
1678-
));
1668+
)
1669+
.await;
16791670

16801671
let start = Instant::now();
16811672

16821673
// Compile benchmarks
16831674
let compile_result = if let Some(compile) = compile {
1684-
let errors = rt.block_on(bench_compile(
1685-
connection.as_mut(),
1686-
&shared,
1687-
compile,
1688-
&collector,
1689-
));
1675+
let errors = bench_compile(connection.as_mut(), &shared, compile, &collector).await;
16901676
errors
16911677
.fail_if_nonzero()
16921678
.context("Compile benchmarks failed")
@@ -1696,30 +1682,32 @@ fn run_benchmarks(
16961682

16971683
// Runtime benchmarks
16981684
let runtime_result = if let Some(runtime) = runtime {
1699-
rt.block_on(bench_runtime(
1685+
bench_runtime(
17001686
connection.as_mut(),
17011687
runtime.runtime_suite,
17021688
&collector,
17031689
runtime.filter,
17041690
runtime.iterations,
1705-
))
1691+
)
1692+
.await
17061693
.context("Runtime benchmarks failed")
17071694
} else {
17081695
Ok(())
17091696
};
17101697

17111698
let end = start.elapsed();
1712-
rt.block_on(connection.record_duration(collector.artifact_row_id, end));
1699+
connection
1700+
.record_duration(collector.artifact_row_id, end)
1701+
.await;
17131702

17141703
compile_result.and(runtime_result)
17151704
}
17161705

17171706
/// Perform benchmarks on a published artifact.
1718-
fn bench_published_artifact(
1707+
async fn bench_published_artifact(
17191708
mut connection: Box<dyn Connection>,
1720-
rt: &mut Runtime,
17211709
toolchain: Toolchain,
1722-
dirs: &BenchmarkDirs,
1710+
dirs: &BenchmarkDirs<'_>,
17231711
) -> anyhow::Result<()> {
17241712
let artifact_id = ArtifactId::Tag(toolchain.id.clone());
17251713

@@ -1738,21 +1726,21 @@ fn bench_published_artifact(
17381726
let mut compile_benchmarks = get_compile_benchmarks(dirs.compile, CompileBenchmarkFilter::All)?;
17391727
compile_benchmarks.retain(|b| b.category().is_stable());
17401728

1741-
let runtime_suite = rt.block_on(load_runtime_benchmarks(
1729+
let runtime_suite = load_runtime_benchmarks(
17421730
connection.as_mut(),
17431731
dirs.runtime,
17441732
CargoIsolationMode::Isolated,
17451733
None,
17461734
&toolchain,
17471735
&artifact_id,
1748-
))?;
1736+
)
1737+
.await?;
17491738

17501739
let shared = SharedBenchmarkConfig {
17511740
artifact_id,
17521741
toolchain,
17531742
};
17541743
run_benchmarks(
1755-
rt,
17561744
connection,
17571745
shared,
17581746
Some(CompileBenchmarkConfig {
@@ -1771,6 +1759,7 @@ fn bench_published_artifact(
17711759
DEFAULT_RUNTIME_ITERATIONS,
17721760
)),
17731761
)
1762+
.await
17741763
}
17751764

17761765
const COMPILE_BENCHMARK_TIMEOUT: Duration = Duration::from_secs(60 * 30);
@@ -1802,6 +1791,7 @@ async fn bench_compile(
18021791

18031792
let start = Instant::now();
18041793

1794+
#[allow(clippy::too_many_arguments)]
18051795
async fn measure_and_record<F: AsyncFn(&mut BenchProcessor) -> anyhow::Result<()>>(
18061796
collector: &CollectorCtx,
18071797
shared: &SharedBenchmarkConfig,
@@ -1989,7 +1979,7 @@ fn get_downloaded_crate_target(benchmark_dir: &Path, cmd: &DownloadCommand) -> P
19891979
.trim_end_matches('/')
19901980
.trim_end_matches(".git")
19911981
.split('/')
1992-
.last()
1982+
.next_back()
19931983
.expect("Crate name could not be determined from git URL")
19941984
.to_string(),
19951985
DownloadSubcommand::Crate { krate, version } => format!("{krate}-{version}"),

site/src/load.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ fn sort_queue(
452452
// are ready to be benchmarked (i.e., those with parent in done or no
453453
// parent).
454454
let level_len = partition_in_place(unordered_queue[finished..].iter_mut(), |(_, mr)| {
455-
mr.parent_sha().map_or(true, |parent| done.contains(parent))
455+
mr.parent_sha().is_none_or(|parent| done.contains(parent))
456456
});
457457

458458
// No commit is ready for benchmarking. This can happen e.g. when a try parent commit

0 commit comments

Comments
 (0)