From e76c12a9db7c3682e799138c5c9a7b1a40d4e588 Mon Sep 17 00:00:00 2001 From: Wilson Lin Date: Sat, 25 Jul 2020 14:18:23 +1000 Subject: [PATCH] Avoid cloning script data before passing to esbuild --- Cargo.toml | 2 +- src/proc/mod.rs | 2 +- src/unit/script.rs | 25 +++++++++++++------------ 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6aed1d8..1c0239f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,6 @@ js-esbuild = ["crossbeam", "esbuild-rs"] [dependencies] crossbeam = { version = "0.7", optional = true } -esbuild-rs = { version = "0.1.3", optional = true } +esbuild-rs = { version = "0.2.1", optional = true } lazy_static = "1.4" memchr = "2" diff --git a/src/proc/mod.rs b/src/proc/mod.rs index 588e5ab..e18b480 100644 --- a/src/proc/mod.rs +++ b/src/proc/mod.rs @@ -339,7 +339,7 @@ impl<'d> Processor<'d> { // Resulting minified JS to write. // TODO Verify. // TODO Rewrite these in esbuild fork so we don't have to do a memcpy and search+replace. - let min_js = result.js.trim().replace(" ProcessingRe if js && cfg.minify_js { let (wg, results) = proc.new_script_section(); let src = start.written_range(proc); - // TODO Optimise: Avoid copying to new Vec. - esbuild_rs::transform(Arc::new(proc[src].to_vec()), TRANSFORM_OPTIONS.clone(), move |result| { - let mut guard = results.lock().unwrap(); - guard.push(JsMinSection { - src, - result, + unsafe { + esbuild_rs::transform_direct_unmanaged(&proc[src], &TRANSFORM_OPTIONS.clone(), move |result| { + let mut guard = results.lock().unwrap(); + guard.push(JsMinSection { + src, + result, + }); + // Drop Arc reference and Mutex guard before marking task as complete as it's possible proc::finish + // waiting on WaitGroup will resume before Arc/Mutex is dropped after exiting this function. + drop(guard); + drop(results); + drop(wg); }); - // Drop Arc reference and Mutex guard before marking task as complete as it's possible proc::finish - // waiting on WaitGroup will resume before Arc/Mutex is dropped after exiting this function. - drop(guard); - drop(results); - drop(wg); - }); + }; return Ok(()); }; break;