Skip to content

Commit b8796fc

Browse files
committed
rayon for minify()
1 parent 66f37d5 commit b8796fc

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

turbopack/crates/turbopack-browser/src/ecmascript/content.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl EcmascriptBrowserChunkContent {
128128
let mut code = code.build();
129129

130130
if let MinifyType::Minify { mangle } = this.chunking_context.await?.minify_type() {
131-
code = minify(&code, source_maps, mangle)?;
131+
code = minify(code, source_maps, mangle).await?;
132132
}
133133

134134
Ok(code.cell())

turbopack/crates/turbopack-browser/src/ecmascript/evaluate/chunk.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ impl EcmascriptBrowserEvaluateChunk {
194194
let mut code = code.build();
195195

196196
if let MinifyType::Minify { mangle } = this.chunking_context.await?.minify_type() {
197-
code = minify(&code, source_maps, mangle)?;
197+
code = minify(code, source_maps, mangle).await?;
198198
}
199199

200200
Ok(code.cell())

turbopack/crates/turbopack-ecmascript/src/minify.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ use turbopack_core::{
3131
use crate::parse::generate_js_source_map;
3232

3333
#[instrument(level = Level::INFO, skip_all)]
34-
pub fn minify(code: &Code, source_maps: bool, mangle: Option<MangleType>) -> Result<Code> {
34+
pub async fn minify(code: Code, source_maps: bool, mangle: Option<MangleType>) -> Result<Code> {
35+
turbo_tasks::spawn_blocking_rayon(move || minify_inner(code, source_maps, mangle)).await
36+
}
37+
38+
fn minify_inner(code: Code, source_maps: bool, mangle: Option<MangleType>) -> Result<Code> {
3539
let source_maps = source_maps
3640
.then(|| code.generate_source_map_ref())
3741
.transpose()?;
@@ -139,8 +143,8 @@ pub fn minify(code: &Code, source_maps: bool, mangle: Option<MangleType>) -> Res
139143
src_map_buf,
140144
Some(original_map),
141145
// We do not inline source contents.
142-
// We provide a synthesized value to `cm.new_source_file` above, so it cannot be
143-
// the value user expect anyway.
146+
// We provide a synthesized value to `cm.new_source_file` above, so it cannot
147+
// be the value user expect anyway.
144148
false,
145149
)?),
146150
);

turbopack/crates/turbopack-nodejs/src/ecmascript/node/content.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl EcmascriptBuildNodeChunkContent {
7878
let mut code = code.build();
7979

8080
if let MinifyType::Minify { mangle } = this.chunking_context.await?.minify_type() {
81-
code = minify(&code, source_maps, mangle)?;
81+
code = minify(code, source_maps, mangle).await?;
8282
}
8383

8484
Ok(code.cell())

0 commit comments

Comments
 (0)