Skip to content

Commit 0783eb8

Browse files
authored
perf: Remove needless Arc (#75601)
### What? Remove one allocation per `transform()` and `minify()`. ### Why? We don't need to allocate `Compiler` in an `Arc`, because we don't share it.
1 parent 576e04c commit 0783eb8

File tree

3 files changed

+4
-8
lines changed

3 files changed

+4
-8
lines changed

crates/napi/src/lib.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ fn init() {
9898
}
9999

100100
#[inline]
101-
fn get_compiler() -> Arc<Compiler> {
101+
fn get_compiler() -> Compiler {
102102
let cm = Arc::new(SourceMap::new(FilePathMapping::empty()));
103103

104-
Arc::new(Compiler::new(cm))
104+
Compiler::new(cm)
105105
}
106106

107107
pub fn complete_output(
@@ -136,8 +136,6 @@ pub fn complete_output(
136136
Ok(js_output)
137137
}
138138

139-
pub type ArcCompiler = Arc<Compiler>;
140-
141139
static REGISTER_ONCE: Once = Once::new();
142140

143141
#[cfg(not(target_arch = "wasm32"))]

crates/napi/src/minify.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
2525
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2626
DEALINGS IN THE SOFTWARE.
2727
*/
28-
use std::sync::Arc;
2928

3029
use napi::bindgen_prelude::*;
3130
use rustc_hash::FxHashMap;
@@ -42,7 +41,7 @@ use swc_core::{
4241
use crate::{get_compiler, util::MapErr};
4342

4443
pub struct MinifyTask {
45-
c: Arc<swc_core::base::Compiler>,
44+
c: swc_core::base::Compiler,
4645
code: MinifyTarget,
4746
opts: swc_core::base::config::JsMinifyOptions,
4847
}

crates/napi/src/transform.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ use std::{
3131
fs::read_to_string,
3232
panic::{catch_unwind, AssertUnwindSafe},
3333
rc::Rc,
34-
sync::Arc,
3534
};
3635

3736
use anyhow::{anyhow, bail, Context as _};
@@ -58,7 +57,7 @@ pub enum Input {
5857
}
5958

6059
pub struct TransformTask {
61-
pub c: Arc<Compiler>,
60+
pub c: Compiler,
6261
pub input: Input,
6362
pub options: Buffer,
6463
}

0 commit comments

Comments
 (0)