Skip to content

Commit

Permalink
refactor(rust): remove unnecessary usage of crossbeam
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
Boshen committed Mar 23, 2023
1 parent 62bad72 commit 9453963
Show file tree
Hide file tree
Showing 10 changed files with 10 additions and 73 deletions.
28 changes: 0 additions & 28 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ better_scoped_tls = { version = "0.1.0" }
bitflags = { version = "1.3.2" }
clap = { version = "4" }
colored = { version = "2.0.0" }
crossbeam = { version = "0.8.1" }
crossbeam-channel = { version = "0.5.6" }
dashmap = { version = "5.4.0" }
derivative = { version = "2.2.0" }
derive_builder = { version = "0.11.2" }
Expand Down
28 changes: 0 additions & 28 deletions crates/node_binding/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion crates/rspack/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ xshell = "0.2.2"
mimalloc-rust = { workspace = true }

[dependencies]
crossbeam = { workspace = true }
dashmap = { workspace = true }
rspack_core = { path = "../rspack_core" }
rspack_fs = { path = "../rspack_fs", features = ["async", "rspack-error"] }
Expand Down
1 change: 0 additions & 1 deletion crates/rspack_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ anyhow = { workspace = true }
async-scoped = { workspace = true, features = ["use-tokio"] }
async-trait = { workspace = true }
bitflags = { workspace = true }
crossbeam = { workspace = true }
dashmap = { workspace = true }
derivative = { workspace = true }
dyn-clone = "1.0.10"
Expand Down
1 change: 0 additions & 1 deletion crates/rspack_loader_sass/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ version = "0.1.0"

[dependencies]
async-trait = { workspace = true }
crossbeam-channel = { workspace = true }
itertools = { workspace = true }
once_cell = { workspace = true }
regex = { workspace = true }
Expand Down
8 changes: 4 additions & 4 deletions crates/rspack_loader_sass/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ use std::{
env,
iter::Peekable,
path::{Path, PathBuf},
sync::Arc,
sync::{mpsc, Arc},
};

use crossbeam_channel::{unbounded, Sender};
use itertools::Itertools;
use once_cell::sync::Lazy;
use regex::Regex;
Expand Down Expand Up @@ -350,7 +349,8 @@ impl LegacyImporter for RspackImporter {

#[derive(Debug)]
struct RspackLogger {
tx: Sender<Vec<Diagnostic>>,
// `Sync` is required by the `Logger` trait
tx: mpsc::SyncSender<Vec<Diagnostic>>,
}

impl Logger for RspackLogger {
Expand Down Expand Up @@ -471,7 +471,7 @@ impl Loader<CompilerContext, CompilationContext> for SassLoader {
loader_context: &mut LoaderContext<'_, '_, CompilerContext, CompilationContext>,
) -> Result<()> {
let content = loader_context.content.to_owned();
let (tx, rx) = unbounded();
let (tx, rx) = mpsc::sync_channel(8);
let logger = RspackLogger { tx };
let sass_options = self.get_sass_options(loader_context, content.try_into_string()?, logger);
let result = Sass::new(&self.options.__exe_path)
Expand Down
1 change: 0 additions & 1 deletion crates/rspack_plugin_javascript/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ async-trait = { workspace = true }
base64 = "0.13"
better_scoped_tls = { workspace = true }
bitflags = { workspace = true }
crossbeam-channel = { workspace = true }
dashmap = { workspace = true }
either = "1"
linked_hash_set = { workspace = true }
Expand Down
6 changes: 3 additions & 3 deletions crates/rspack_plugin_javascript/src/ast/minify.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::sync::Arc;
use std::sync::{mpsc, Arc};

use rspack_core::ModuleType;
use rspack_error::{internal_error, DiagnosticKind, Error, Result, TraceableError};
Expand Down Expand Up @@ -235,7 +235,7 @@ fn minify_file_comments(

// keep this private to make sure with_rspack_error_handler is safety
struct RspackErrorEmitter {
tx: crossbeam_channel::Sender<rspack_error::Error>,
tx: mpsc::Sender<rspack_error::Error>,
source_map: Arc<SourceMap>,
title: String,
kind: DiagnosticKind,
Expand Down Expand Up @@ -279,7 +279,7 @@ pub fn with_rspack_error_handler<F, Ret>(
where
F: FnOnce(&Handler) -> Result<Ret>,
{
let (tx, rx) = crossbeam_channel::unbounded();
let (tx, rx) = mpsc::channel();
let emitter = RspackErrorEmitter {
title,
kind,
Expand Down
7 changes: 3 additions & 4 deletions crates/rspack_plugin_javascript/src/plugin.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::hash::{Hash, Hasher};
use std::sync::mpsc;

use async_trait::async_trait;
use crossbeam_channel::unbounded;
use rayon::prelude::*;
use rspack_core::rspack_sources::{
BoxSource, ConcatSource, MapOptions, RawSource, Source, SourceExt, SourceMap, SourceMapSource,
Expand Down Expand Up @@ -519,15 +519,15 @@ impl Plugin for JsPlugin {
let minify_options = &compilation.options.builtins.minify_options;

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

compilation
.assets
.par_iter_mut()
.filter(|(filename, _)| {
filename.ends_with(".js") || filename.ends_with(".cjs") || filename.ends_with(".mjs")
})
.try_for_each(|(filename, original)| -> Result<()> {
.try_for_each_with(tx, |tx, (filename, original)| -> Result<()> {
// In theory, if a js source is minimized it has high possibility has been tree-shaked.
if original.get_info().minimized {
return Ok(());
Expand Down Expand Up @@ -574,7 +574,6 @@ impl Plugin for JsPlugin {
Ok(())
})?;

drop(tx);
compilation.push_batch_diagnostic(rx.into_iter().flatten().collect::<Vec<_>>());
}

Expand Down

0 comments on commit 9453963

Please sign in to comment.