Skip to content

Commit 9453963

Browse files
committed
refactor(rust): remove unnecessary usage of crossbeam
This removes a large dependency which should improve our build speed a bit. Note: mpsc::channel is now a port of crossbeam, they have no difference. See: `https://github.com/rust-lang/rust/pull/93563`
1 parent 62bad72 commit 9453963

File tree

10 files changed

+10
-73
lines changed

10 files changed

+10
-73
lines changed

Cargo.lock

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

Cargo.toml

-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ better_scoped_tls = { version = "0.1.0" }
2424
bitflags = { version = "1.3.2" }
2525
clap = { version = "4" }
2626
colored = { version = "2.0.0" }
27-
crossbeam = { version = "0.8.1" }
28-
crossbeam-channel = { version = "0.5.6" }
2927
dashmap = { version = "5.4.0" }
3028
derivative = { version = "2.2.0" }
3129
derive_builder = { version = "0.11.2" }

crates/node_binding/Cargo.lock

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

crates/rspack/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ xshell = "0.2.2"
2222
mimalloc-rust = { workspace = true }
2323

2424
[dependencies]
25-
crossbeam = { workspace = true }
2625
dashmap = { workspace = true }
2726
rspack_core = { path = "../rspack_core" }
2827
rspack_fs = { path = "../rspack_fs", features = ["async", "rspack-error"] }

crates/rspack_core/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ anyhow = { workspace = true }
1010
async-scoped = { workspace = true, features = ["use-tokio"] }
1111
async-trait = { workspace = true }
1212
bitflags = { workspace = true }
13-
crossbeam = { workspace = true }
1413
dashmap = { workspace = true }
1514
derivative = { workspace = true }
1615
dyn-clone = "1.0.10"

crates/rspack_loader_sass/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ version = "0.1.0"
99

1010
[dependencies]
1111
async-trait = { workspace = true }
12-
crossbeam-channel = { workspace = true }
1312
itertools = { workspace = true }
1413
once_cell = { workspace = true }
1514
regex = { workspace = true }

crates/rspack_loader_sass/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ use std::{
44
env,
55
iter::Peekable,
66
path::{Path, PathBuf},
7-
sync::Arc,
7+
sync::{mpsc, Arc},
88
};
99

10-
use crossbeam_channel::{unbounded, Sender};
1110
use itertools::Itertools;
1211
use once_cell::sync::Lazy;
1312
use regex::Regex;
@@ -350,7 +349,8 @@ impl LegacyImporter for RspackImporter {
350349

351350
#[derive(Debug)]
352351
struct RspackLogger {
353-
tx: Sender<Vec<Diagnostic>>,
352+
// `Sync` is required by the `Logger` trait
353+
tx: mpsc::SyncSender<Vec<Diagnostic>>,
354354
}
355355

356356
impl Logger for RspackLogger {
@@ -471,7 +471,7 @@ impl Loader<CompilerContext, CompilationContext> for SassLoader {
471471
loader_context: &mut LoaderContext<'_, '_, CompilerContext, CompilationContext>,
472472
) -> Result<()> {
473473
let content = loader_context.content.to_owned();
474-
let (tx, rx) = unbounded();
474+
let (tx, rx) = mpsc::sync_channel(8);
475475
let logger = RspackLogger { tx };
476476
let sass_options = self.get_sass_options(loader_context, content.try_into_string()?, logger);
477477
let result = Sass::new(&self.options.__exe_path)

crates/rspack_plugin_javascript/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ async-trait = { workspace = true }
1414
base64 = "0.13"
1515
better_scoped_tls = { workspace = true }
1616
bitflags = { workspace = true }
17-
crossbeam-channel = { workspace = true }
1817
dashmap = { workspace = true }
1918
either = "1"
2019
linked_hash_set = { workspace = true }

crates/rspack_plugin_javascript/src/ast/minify.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::sync::Arc;
1+
use std::sync::{mpsc, Arc};
22

33
use rspack_core::ModuleType;
44
use rspack_error::{internal_error, DiagnosticKind, Error, Result, TraceableError};
@@ -235,7 +235,7 @@ fn minify_file_comments(
235235

236236
// keep this private to make sure with_rspack_error_handler is safety
237237
struct RspackErrorEmitter {
238-
tx: crossbeam_channel::Sender<rspack_error::Error>,
238+
tx: mpsc::Sender<rspack_error::Error>,
239239
source_map: Arc<SourceMap>,
240240
title: String,
241241
kind: DiagnosticKind,
@@ -279,7 +279,7 @@ pub fn with_rspack_error_handler<F, Ret>(
279279
where
280280
F: FnOnce(&Handler) -> Result<Ret>,
281281
{
282-
let (tx, rx) = crossbeam_channel::unbounded();
282+
let (tx, rx) = mpsc::channel();
283283
let emitter = RspackErrorEmitter {
284284
title,
285285
kind,

crates/rspack_plugin_javascript/src/plugin.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::hash::{Hash, Hasher};
2+
use std::sync::mpsc;
23

34
use async_trait::async_trait;
4-
use crossbeam_channel::unbounded;
55
use rayon::prelude::*;
66
use rspack_core::rspack_sources::{
77
BoxSource, ConcatSource, MapOptions, RawSource, Source, SourceExt, SourceMap, SourceMapSource,
@@ -519,15 +519,15 @@ impl Plugin for JsPlugin {
519519
let minify_options = &compilation.options.builtins.minify_options;
520520

521521
if let Some(minify_options) = minify_options {
522-
let (tx, rx) = unbounded::<Vec<Diagnostic>>();
522+
let (tx, rx) = mpsc::channel::<Vec<Diagnostic>>();
523523

524524
compilation
525525
.assets
526526
.par_iter_mut()
527527
.filter(|(filename, _)| {
528528
filename.ends_with(".js") || filename.ends_with(".cjs") || filename.ends_with(".mjs")
529529
})
530-
.try_for_each(|(filename, original)| -> Result<()> {
530+
.try_for_each_with(tx, |tx, (filename, original)| -> Result<()> {
531531
// In theory, if a js source is minimized it has high possibility has been tree-shaked.
532532
if original.get_info().minimized {
533533
return Ok(());
@@ -574,7 +574,6 @@ impl Plugin for JsPlugin {
574574
Ok(())
575575
})?;
576576

577-
drop(tx);
578577
compilation.push_batch_diagnostic(rx.into_iter().flatten().collect::<Vec<_>>());
579578
}
580579

0 commit comments

Comments
 (0)