Skip to content

Commit 93b318f

Browse files
authored
perf(swc_error_reporters): Avoid creating miette handler when no diagnostics (#10852)
**Description:** Automatically prevent the creation of `miette::GraphicalReportHandler when no diagnostics are present. **Related issue:** See performance regression in web-infra-dev/rspack#11006
1 parent 22f351f commit 93b318f

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

crates/swc_error_reporters/src/handler.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,18 @@ impl ThreadSafetyDiagnostics {
8787
skip_filename: bool,
8888
color: ColorConfig,
8989
) -> Vec<String> {
90-
let handler = to_pretty_handler(color);
91-
self.0
90+
let diagnostics = self
91+
.0
9292
.lock()
93-
.expect("Failed to access the diagnostics lock")
93+
.expect("Failed to access the diagnostics lock");
94+
95+
// If there are no diagnostics, return empty vector without initializing handler
96+
if diagnostics.is_empty() {
97+
return Vec::new();
98+
}
99+
100+
let handler = to_pretty_handler(color);
101+
diagnostics
94102
.iter()
95103
.map(|d| d.to_pretty_string(cm, skip_filename, &handler))
96104
.collect::<Vec<String>>()

0 commit comments

Comments
 (0)