From be46f91d6261eb88b6e04364d912f6cb39b1a26c Mon Sep 17 00:00:00 2001 From: Qingyu Wang <40660121+colinaaa@users.noreply.github.com> Date: Mon, 14 Jul 2025 20:09:32 +0800 Subject: [PATCH] perf(swc_error_reporters): avoid initilizing mitte handler when no diagnostics --- crates/swc_error_reporters/src/handler.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/crates/swc_error_reporters/src/handler.rs b/crates/swc_error_reporters/src/handler.rs index e28eb1f3dd21..5e1a87eed27f 100644 --- a/crates/swc_error_reporters/src/handler.rs +++ b/crates/swc_error_reporters/src/handler.rs @@ -87,10 +87,18 @@ impl ThreadSafetyDiagnostics { skip_filename: bool, color: ColorConfig, ) -> Vec { - let handler = to_pretty_handler(color); - self.0 + let diagnostics = self + .0 .lock() - .expect("Failed to access the diagnostics lock") + .expect("Failed to access the diagnostics lock"); + + // If there are no diagnostics, return empty vector without initializing handler + if diagnostics.is_empty() { + return Vec::new(); + } + + let handler = to_pretty_handler(color); + diagnostics .iter() .map(|d| d.to_pretty_string(cm, skip_filename, &handler)) .collect::>()