From c22c4870267e0e9e9623c5ae5b931f8995c43c58 Mon Sep 17 00:00:00 2001 From: hardfist Date: Thu, 31 Oct 2024 20:18:11 +0800 Subject: [PATCH 1/4] feat(core): improve progress plugin for multi compiler --- Cargo.lock | 5 +++-- crates/rspack_plugin_progress/Cargo.toml | 1 + crates/rspack_plugin_progress/src/lib.rs | 10 +++++++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ccaa29eed76..d323f5ebb1c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2121,9 +2121,9 @@ dependencies = [ [[package]] name = "lazy_static" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "leb128" @@ -4383,6 +4383,7 @@ version = "0.1.0" dependencies = [ "async-trait", "indicatif", + "lazy_static", "rspack_collections", "rspack_core", "rspack_error", diff --git a/crates/rspack_plugin_progress/Cargo.toml b/crates/rspack_plugin_progress/Cargo.toml index 77ac96a168c..8dfaf391714 100644 --- a/crates/rspack_plugin_progress/Cargo.toml +++ b/crates/rspack_plugin_progress/Cargo.toml @@ -10,6 +10,7 @@ version = "0.1.0" [dependencies] async-trait = { workspace = true } indicatif = "0.17.8" +lazy_static = { version = "1.5.0" } rspack_collections = { version = "0.1.0", path = "../rspack_collections" } rspack_core = { version = "0.1.0", path = "../rspack_core" } rspack_error = { version = "0.1.0", path = "../rspack_error" } diff --git a/crates/rspack_plugin_progress/src/lib.rs b/crates/rspack_plugin_progress/src/lib.rs index 2ac2d585dd1..0fff0799124 100644 --- a/crates/rspack_plugin_progress/src/lib.rs +++ b/crates/rspack_plugin_progress/src/lib.rs @@ -1,11 +1,12 @@ use std::cmp::Ordering; use std::sync::atomic::Ordering::Relaxed; -use std::sync::{Arc, RwLock}; +use std::sync::{Arc, Mutex, RwLock}; use std::time::{Duration, SystemTime, UNIX_EPOCH}; use std::{cmp, sync::atomic::AtomicU32, time::Instant}; use async_trait::async_trait; -use indicatif::{ProgressBar, ProgressDrawTarget, ProgressStyle}; +use indicatif::{MultiProgress, ProgressBar, ProgressDrawTarget, ProgressStyle}; +use lazy_static::lazy_static; use rspack_collections::IdentifierMap; use rspack_core::{ ApplyContext, BoxModule, Compilation, CompilationAfterOptimizeModules, @@ -41,6 +42,9 @@ impl std::fmt::Debug for ProgressPluginOptions { } } +lazy_static! { + static ref MULTI_PROGRESS: Arc> = Arc::new(Mutex::new(MultiProgress::new())); +} #[derive(Debug, Default)] pub struct ProgressPluginDisplayOptions { // the prefix name of progress bar @@ -101,7 +105,7 @@ impl ProgressPlugin { Some(progress_bar) } }; - + let progress_bar = progress_bar.map(|x| MULTI_PROGRESS.lock().unwrap().add(x)); Self::new_inner( options, progress_bar, From b397856535cbbe0f39df98d162df03c1bfed1aef Mon Sep 17 00:00:00 2001 From: hardfist Date: Thu, 31 Oct 2024 20:31:00 +0800 Subject: [PATCH 2/4] chore: fix clippy --- crates/rspack_plugin_progress/src/lib.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/rspack_plugin_progress/src/lib.rs b/crates/rspack_plugin_progress/src/lib.rs index 0fff0799124..a3ac3cb9329 100644 --- a/crates/rspack_plugin_progress/src/lib.rs +++ b/crates/rspack_plugin_progress/src/lib.rs @@ -105,7 +105,12 @@ impl ProgressPlugin { Some(progress_bar) } }; - let progress_bar = progress_bar.map(|x| MULTI_PROGRESS.lock().unwrap().add(x)); + let progress_bar = progress_bar.map(|x| { + MULTI_PROGRESS + .lock() + .expect("multi progress lock failed") + .add(x) + }); Self::new_inner( options, progress_bar, From d59e956dd920ccb4b5c8caffb02cd857e8b7b982 Mon Sep 17 00:00:00 2001 From: hardfist Date: Thu, 31 Oct 2024 21:04:31 +0800 Subject: [PATCH 3/4] chore: use lazylock --- Cargo.lock | 1 - crates/rspack_plugin_progress/Cargo.toml | 1 - crates/rspack_plugin_progress/src/lib.rs | 14 +++----------- 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d323f5ebb1c..0565289c1e6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4383,7 +4383,6 @@ version = "0.1.0" dependencies = [ "async-trait", "indicatif", - "lazy_static", "rspack_collections", "rspack_core", "rspack_error", diff --git a/crates/rspack_plugin_progress/Cargo.toml b/crates/rspack_plugin_progress/Cargo.toml index 8dfaf391714..77ac96a168c 100644 --- a/crates/rspack_plugin_progress/Cargo.toml +++ b/crates/rspack_plugin_progress/Cargo.toml @@ -10,7 +10,6 @@ version = "0.1.0" [dependencies] async-trait = { workspace = true } indicatif = "0.17.8" -lazy_static = { version = "1.5.0" } rspack_collections = { version = "0.1.0", path = "../rspack_collections" } rspack_core = { version = "0.1.0", path = "../rspack_core" } rspack_error = { version = "0.1.0", path = "../rspack_error" } diff --git a/crates/rspack_plugin_progress/src/lib.rs b/crates/rspack_plugin_progress/src/lib.rs index a3ac3cb9329..3d49cc5ab07 100644 --- a/crates/rspack_plugin_progress/src/lib.rs +++ b/crates/rspack_plugin_progress/src/lib.rs @@ -1,12 +1,11 @@ use std::cmp::Ordering; use std::sync::atomic::Ordering::Relaxed; -use std::sync::{Arc, Mutex, RwLock}; +use std::sync::{Arc, LazyLock, RwLock}; use std::time::{Duration, SystemTime, UNIX_EPOCH}; use std::{cmp, sync::atomic::AtomicU32, time::Instant}; use async_trait::async_trait; use indicatif::{MultiProgress, ProgressBar, ProgressDrawTarget, ProgressStyle}; -use lazy_static::lazy_static; use rspack_collections::IdentifierMap; use rspack_core::{ ApplyContext, BoxModule, Compilation, CompilationAfterOptimizeModules, @@ -42,9 +41,7 @@ impl std::fmt::Debug for ProgressPluginOptions { } } -lazy_static! { - static ref MULTI_PROGRESS: Arc> = Arc::new(Mutex::new(MultiProgress::new())); -} +static MULTI_PROGRESS: LazyLock = LazyLock::new(|| MultiProgress::new()); #[derive(Debug, Default)] pub struct ProgressPluginDisplayOptions { // the prefix name of progress bar @@ -105,12 +102,7 @@ impl ProgressPlugin { Some(progress_bar) } }; - let progress_bar = progress_bar.map(|x| { - MULTI_PROGRESS - .lock() - .expect("multi progress lock failed") - .add(x) - }); + let progress_bar = progress_bar.map(|x| MULTI_PROGRESS.add(x)); Self::new_inner( options, progress_bar, From 53d5a9c0cec6c2dde2301cb564722a101ea9c458 Mon Sep 17 00:00:00 2001 From: hardfist Date: Thu, 31 Oct 2024 21:13:47 +0800 Subject: [PATCH 4/4] chore: fix clippy --- crates/rspack_plugin_progress/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/rspack_plugin_progress/src/lib.rs b/crates/rspack_plugin_progress/src/lib.rs index 3d49cc5ab07..2ed58772ac7 100644 --- a/crates/rspack_plugin_progress/src/lib.rs +++ b/crates/rspack_plugin_progress/src/lib.rs @@ -41,7 +41,7 @@ impl std::fmt::Debug for ProgressPluginOptions { } } -static MULTI_PROGRESS: LazyLock = LazyLock::new(|| MultiProgress::new()); +static MULTI_PROGRESS: LazyLock = LazyLock::new(MultiProgress::new); #[derive(Debug, Default)] pub struct ProgressPluginDisplayOptions { // the prefix name of progress bar