diff --git a/.changeset/hip-spiders-own.md b/.changeset/hip-spiders-own.md new file mode 100644 index 000000000000..df89434fc879 --- /dev/null +++ b/.changeset/hip-spiders-own.md @@ -0,0 +1,8 @@ +--- +swc_compiler_base: patch +swc_ecma_codegen: patch +swc_ecma_transforms_react: patch +swc_fast_ts_strip: patch +--- + +perf(es/codegen): Use `Vec` from `swc_allocator` diff --git a/crates/swc_compiler_base/src/lib.rs b/crates/swc_compiler_base/src/lib.rs index ba870df5cac7..e71403aaa2c4 100644 --- a/crates/swc_compiler_base/src/lib.rs +++ b/crates/swc_compiler_base/src/lib.rs @@ -9,6 +9,7 @@ use once_cell::sync::Lazy; use rustc_hash::FxHashMap; #[allow(unused)] use serde::{Deserialize, Serialize}; +use swc_allocator::maybe::vec::Vec; use swc_atoms::JsWord; use swc_common::{ collections::AHashMap, diff --git a/crates/swc_ecma_codegen/Cargo.toml b/crates/swc_ecma_codegen/Cargo.toml index 73160af70633..f0c9db97d933 100644 --- a/crates/swc_ecma_codegen/Cargo.toml +++ b/crates/swc_ecma_codegen/Cargo.toml @@ -37,6 +37,7 @@ codspeed-criterion-compat = { workspace = true } criterion = { workspace = true } serde_json = { workspace = true } +swc_allocator = { version = "0.1.7", path = "../swc_allocator" } swc_common = { version = "0.36.0", path = "../swc_common", features = [ "sourcemap", ] } diff --git a/crates/swc_ecma_codegen/benches/bench.rs b/crates/swc_ecma_codegen/benches/bench.rs index 01ffdd3bae7f..0be710f30462 100644 --- a/crates/swc_ecma_codegen/benches/bench.rs +++ b/crates/swc_ecma_codegen/benches/bench.rs @@ -1,6 +1,7 @@ extern crate swc_malloc; use codspeed_criterion_compat::{black_box, criterion_group, criterion_main, Bencher, Criterion}; +use swc_allocator::{maybe::vec::Vec, Allocator}; use swc_common::FileName; use swc_ecma_codegen::Emitter; use swc_ecma_parser::{Parser, StringInput, Syntax}; @@ -94,6 +95,9 @@ fn bench_emitter(b: &mut Bencher, s: &str) { } b.iter(|| { + let alloc = Allocator::default(); + let mut _guard = unsafe { alloc.guard() }; + let mut src_map_buf = Vec::new(); let mut buf = Vec::new(); { diff --git a/crates/swc_ecma_codegen/benches/with_parse.rs b/crates/swc_ecma_codegen/benches/with_parse.rs index dc3a2aa7c948..f4088e458c89 100644 --- a/crates/swc_ecma_codegen/benches/with_parse.rs +++ b/crates/swc_ecma_codegen/benches/with_parse.rs @@ -1,6 +1,7 @@ extern crate swc_malloc; use codspeed_criterion_compat::{black_box, criterion_group, criterion_main, Bencher, Criterion}; +use swc_allocator::maybe::vec::Vec; use swc_common::FileName; use swc_ecma_codegen::Emitter; use swc_ecma_parser::{Parser, StringInput, Syntax}; diff --git a/crates/swc_ecma_codegen/examples/sourcemap.rs b/crates/swc_ecma_codegen/examples/sourcemap.rs index 09f93cb74eb7..4b60536dac59 100644 --- a/crates/swc_ecma_codegen/examples/sourcemap.rs +++ b/crates/swc_ecma_codegen/examples/sourcemap.rs @@ -9,6 +9,7 @@ use std::{ time::Instant, }; +use swc_allocator::maybe::vec::Vec; use swc_common::input::SourceFileInput; use swc_ecma_ast::*; use swc_ecma_codegen::{text_writer::JsWriter, Emitter}; diff --git a/crates/swc_ecma_codegen/src/text_writer/basic_impl.rs b/crates/swc_ecma_codegen/src/text_writer/basic_impl.rs index e21389cc474f..2da27b267470 100644 --- a/crates/swc_ecma_codegen/src/text_writer/basic_impl.rs +++ b/crates/swc_ecma_codegen/src/text_writer/basic_impl.rs @@ -1,6 +1,7 @@ use std::io::Write; use rustc_hash::FxHashSet; +use swc_allocator::maybe::vec::Vec; use swc_common::{sync::Lrc, BytePos, LineCol, SourceMap, Span}; use super::{Result, WriteJs}; diff --git a/crates/swc_ecma_codegen/tests/sourcemap.rs b/crates/swc_ecma_codegen/tests/sourcemap.rs index dc8a30cf8ec7..ec8c9c1a4208 100644 --- a/crates/swc_ecma_codegen/tests/sourcemap.rs +++ b/crates/swc_ecma_codegen/tests/sourcemap.rs @@ -3,6 +3,7 @@ use std::{fs::read_to_string, path::PathBuf}; use base64::prelude::{Engine, BASE64_STANDARD}; use rustc_hash::FxHashSet; use sourcemap::SourceMap; +use swc_allocator::maybe::vec::Vec; use swc_common::{comments::SingleThreadedComments, source_map::SourceMapGenConfig}; use swc_ecma_ast::EsVersion; use swc_ecma_codegen::{text_writer::WriteJs, Emitter}; diff --git a/crates/swc_ecma_transforms_react/src/pure_annotations/tests.rs b/crates/swc_ecma_transforms_react/src/pure_annotations/tests.rs index e97a3eef0161..ed6162833fc7 100644 --- a/crates/swc_ecma_transforms_react/src/pure_annotations/tests.rs +++ b/crates/swc_ecma_transforms_react/src/pure_annotations/tests.rs @@ -1,3 +1,4 @@ +use swc_allocator::maybe::vec::Vec; use swc_common::{comments::SingleThreadedComments, sync::Lrc, FileName, Mark, SourceMap}; use swc_ecma_codegen::{text_writer::JsWriter, Emitter}; use swc_ecma_parser::{Parser, StringInput}; diff --git a/crates/swc_fast_ts_strip/src/lib.rs b/crates/swc_fast_ts_strip/src/lib.rs index f383b77c51e3..887a22cc184f 100644 --- a/crates/swc_fast_ts_strip/src/lib.rs +++ b/crates/swc_fast_ts_strip/src/lib.rs @@ -2,6 +2,7 @@ use std::{cell::RefCell, rc::Rc}; use anyhow::{Context, Error}; use serde::{Deserialize, Serialize}; +use swc_allocator::maybe::vec::Vec; use swc_common::{ comments::SingleThreadedComments, errors::{Handler, HANDLER},