Skip to content

Commit 4d39480

Browse files
refactor(cli): process-reports: use rayon and channels to parallelize report parsing
1 parent bfe2e1e commit 4d39480

File tree

3 files changed

+106
-25
lines changed

3 files changed

+106
-25
lines changed

Cargo.lock

+75
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ log = "0.4.20"
2424
miette = { version = "5.10.0", features = ["fancy"] }
2525
natord = "1.0.9"
2626
path-dsl = "0.6.1"
27+
rayon = "1.8.0"
2728
regex = "1.9.5"
2829
serde = { version = "1.0.188", features = ["derive"] }
2930
serde_json = "1.0.107"

src/bin/moz-webgpu-cts/main.rs

+30-25
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use std::{
2121
num::NonZeroU64,
2222
path::{Path, PathBuf},
2323
process::ExitCode,
24-
sync::Arc,
24+
sync::{mpsc::channel, Arc},
2525
};
2626

2727
use clap::Parser;
@@ -30,6 +30,7 @@ use indexmap::{IndexMap, IndexSet};
3030
use miette::{miette, Diagnostic, IntoDiagnostic, NamedSource, Report, SourceSpan, WrapErr};
3131
use path_dsl::path;
3232

33+
use rayon::prelude::{IntoParallelIterator, ParallelIterator};
3334
use regex::Regex;
3435
use wax::Glob;
3536
use whippit::{
@@ -347,30 +348,34 @@ fn run(cli: Cli) -> ExitCode {
347348

348349
log::info!("gathering reported test outcomes for comparison to metadata…");
349350

350-
let exec_reports_iter = exec_report_paths.iter().map(|path| {
351-
fs::File::open(path)
352-
.map(BufReader::new)
353-
.map_err(Report::msg)
354-
.wrap_err("failed to open file")
355-
.and_then(|reader| {
356-
serde_json::from_reader::<_, ExecutionReport>(reader)
357-
.into_diagnostic()
358-
.wrap_err("failed to parse JSON")
359-
})
360-
.map(|parsed| (path, parsed))
361-
.wrap_err_with(|| {
362-
format!(
363-
"failed to read WPT execution report from {}",
364-
path.display()
365-
)
366-
})
367-
.map_err(|e| {
368-
log::error!("{e:?}");
369-
AlreadyReportedToCommandline
370-
})
371-
});
372-
373-
for res in exec_reports_iter {
351+
let (exec_reports_sender, exec_reports_receiver) = channel();
352+
exec_report_paths
353+
.into_par_iter()
354+
.for_each_with(exec_reports_sender, |sender, path| {
355+
let res = fs::File::open(&path)
356+
.map(BufReader::new)
357+
.map_err(Report::msg)
358+
.wrap_err("failed to open file")
359+
.and_then(|reader| {
360+
serde_json::from_reader::<_, ExecutionReport>(reader)
361+
.into_diagnostic()
362+
.wrap_err("failed to parse JSON")
363+
})
364+
.wrap_err_with(|| {
365+
format!(
366+
"failed to read WPT execution report from {}",
367+
path.display()
368+
)
369+
})
370+
.map(|parsed| (path, parsed))
371+
.map_err(|e| {
372+
log::error!("{e:?}");
373+
AlreadyReportedToCommandline
374+
});
375+
let _ = sender.send(res);
376+
});
377+
378+
for res in exec_reports_receiver {
374379
let (_path, exec_report) = match res {
375380
Ok(ok) => ok,
376381
Err(AlreadyReportedToCommandline) => return ExitCode::FAILURE,

0 commit comments

Comments
 (0)