From c5edddbf7b470657c86649521310a236fbd759a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Wed, 17 Jul 2024 19:03:18 +0900 Subject: [PATCH] Revert "perf(es/codegen): Use scoped allocator (#9248)" This reverts commit 970f32398c6ff444540a31e1172a33b6155ed18b. --- Cargo.lock | 5 ----- crates/swc_compiler_base/Cargo.toml | 1 - crates/swc_compiler_base/src/lib.rs | 4 ++-- crates/swc_ecma_ast/src/stmt.rs | 2 +- crates/swc_ecma_codegen/Cargo.toml | 1 - crates/swc_ecma_codegen/benches/bench.rs | 8 ++------ crates/swc_ecma_codegen/benches/with_parse.rs | 3 +-- crates/swc_ecma_codegen/examples/sourcemap.rs | 5 ++--- crates/swc_ecma_codegen/src/tests.rs | 5 ++--- crates/swc_ecma_codegen/src/text_writer/basic_impl.rs | 1 - crates/swc_ecma_codegen/tests/sourcemap.rs | 3 +-- crates/swc_ecma_transforms_base/Cargo.toml | 1 - crates/swc_ecma_transforms_react/Cargo.toml | 1 - .../src/pure_annotations/tests.rs | 5 ++--- crates/swc_fast_ts_strip/Cargo.toml | 1 - crates/swc_fast_ts_strip/src/lib.rs | 2 +- 16 files changed, 14 insertions(+), 34 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dda7b04ba9cb..5521aad221bc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3841,7 +3841,6 @@ dependencies = [ "serde", "serde_json", "sourcemap", - "swc_allocator", "swc_atoms", "swc_common", "swc_config", @@ -4152,7 +4151,6 @@ dependencies = [ "serde", "serde_json", "sourcemap", - "swc_allocator", "swc_atoms", "swc_common", "swc_ecma_ast", @@ -4594,7 +4592,6 @@ dependencies = [ "rustc-hash", "serde", "smallvec", - "swc_allocator", "swc_atoms", "swc_common", "swc_ecma_ast", @@ -4766,7 +4763,6 @@ dependencies = [ "serde", "sha1", "string_enum", - "swc_allocator", "swc_atoms", "swc_common", "swc_config", @@ -4970,7 +4966,6 @@ dependencies = [ "codspeed-criterion-compat", "criterion", "serde", - "swc_allocator", "swc_common", "swc_ecma_ast", "swc_ecma_codegen", diff --git a/crates/swc_compiler_base/Cargo.toml b/crates/swc_compiler_base/Cargo.toml index de1cc23e7ea5..b5fe3380427a 100644 --- a/crates/swc_compiler_base/Cargo.toml +++ b/crates/swc_compiler_base/Cargo.toml @@ -21,7 +21,6 @@ rustc-hash = { workspace = true } serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true } sourcemap = { workspace = true } -swc_allocator = { version = "0.1.5", path = "../swc_allocator", default-features = false } swc_atoms = { version = "0.6.5", path = "../swc_atoms" } swc_common = { version = "0.35.0", path = "../swc_common", features = [ diff --git a/crates/swc_compiler_base/src/lib.rs b/crates/swc_compiler_base/src/lib.rs index 60592cae351a..2def122b13ba 100644 --- a/crates/swc_compiler_base/src/lib.rs +++ b/crates/swc_compiler_base/src/lib.rs @@ -171,10 +171,10 @@ where { let _timer = timer!("Compiler::print"); - let mut src_map_buf = swc_allocator::vec::Vec::new(); + let mut src_map_buf = vec![]; let src = { - let mut buf = Vec::new(); + let mut buf = vec![]; { let mut w = swc_ecma_codegen::text_writer::JsWriter::new( cm.clone(), diff --git a/crates/swc_ecma_ast/src/stmt.rs b/crates/swc_ecma_ast/src/stmt.rs index c19460bbcf7f..32665b359a73 100644 --- a/crates/swc_ecma_ast/src/stmt.rs +++ b/crates/swc_ecma_ast/src/stmt.rs @@ -164,7 +164,7 @@ impl Stmt { } } -// Memory layout depends on the version of rustc. +// Memory layout depedns on the version of rustc. // #[cfg(target_pointer_width = "64")] // assert_eq_size!(Stmt, [u8; 56]); diff --git a/crates/swc_ecma_codegen/Cargo.toml b/crates/swc_ecma_codegen/Cargo.toml index 7a0ad7458835..2021beddcc2d 100644 --- a/crates/swc_ecma_codegen/Cargo.toml +++ b/crates/swc_ecma_codegen/Cargo.toml @@ -25,7 +25,6 @@ serde = { workspace = true } sourcemap = { workspace = true } tracing = { workspace = true } -swc_allocator = { version = "0.1.5", path = "../swc_allocator" } swc_atoms = { version = "0.6.5", path = "../swc_atoms" } swc_common = { version = "0.35.0", path = "../swc_common" } swc_ecma_ast = { version = "0.116.0", path = "../swc_ecma_ast" } diff --git a/crates/swc_ecma_codegen/benches/bench.rs b/crates/swc_ecma_codegen/benches/bench.rs index af47725357e4..9c820aeeac3c 100644 --- a/crates/swc_ecma_codegen/benches/bench.rs +++ b/crates/swc_ecma_codegen/benches/bench.rs @@ -1,7 +1,6 @@ extern crate swc_malloc; use codspeed_criterion_compat::{black_box, criterion_group, criterion_main, Bencher, Criterion}; -use swc_allocator::{vec::Vec, Allocator}; use swc_common::FileName; use swc_ecma_codegen::Emitter; use swc_ecma_parser::{Parser, StringInput, Syntax}; @@ -85,6 +84,7 @@ fn bench_emitter(b: &mut Bencher, s: &str) { let fm = cm.new_source_file(FileName::Anon.into(), s.into()); let mut parser = Parser::new(Syntax::default(), StringInput::from(&*fm), None); + let mut src_map_buf = vec![]; let module = parser .parse_module() .map_err(|e| e.into_diagnostic(handler).emit()) @@ -95,11 +95,7 @@ fn bench_emitter(b: &mut Bencher, s: &str) { } b.iter(|| { - let alloc = Allocator::default(); - let _guard = unsafe { alloc.guard() }; - let mut src_map_buf = Vec::new(); - - let mut buf = Vec::new(); + let mut buf = vec![]; { let mut emitter = Emitter { cfg: Default::default(), diff --git a/crates/swc_ecma_codegen/benches/with_parse.rs b/crates/swc_ecma_codegen/benches/with_parse.rs index a08132e44f6a..d0ff27b97d61 100644 --- a/crates/swc_ecma_codegen/benches/with_parse.rs +++ b/crates/swc_ecma_codegen/benches/with_parse.rs @@ -1,7 +1,6 @@ extern crate swc_malloc; use codspeed_criterion_compat::{black_box, criterion_group, criterion_main, Bencher, Criterion}; -use swc_allocator::vec::Vec; use swc_common::FileName; use swc_ecma_codegen::Emitter; use swc_ecma_parser::{Parser, StringInput, Syntax}; @@ -85,7 +84,7 @@ fn bench_emitter(b: &mut Bencher, s: &str) { b.iter(|| { let fm = cm.new_source_file(FileName::Anon.into(), s.into()); let mut parser = Parser::new(Syntax::default(), StringInput::from(&*fm), None); - let mut src_map_buf = Vec::new(); + let mut src_map_buf = vec![]; let module = parser .parse_module() .map_err(|e| e.into_diagnostic(handler).emit()) diff --git a/crates/swc_ecma_codegen/examples/sourcemap.rs b/crates/swc_ecma_codegen/examples/sourcemap.rs index 1f004bb406cd..e18522086244 100644 --- a/crates/swc_ecma_codegen/examples/sourcemap.rs +++ b/crates/swc_ecma_codegen/examples/sourcemap.rs @@ -9,7 +9,6 @@ use std::{ time::Instant, }; -use swc_allocator::vec::Vec; use swc_common::input::SourceFileInput; use swc_ecma_ast::*; use swc_ecma_codegen::{text_writer::JsWriter, Emitter}; @@ -31,7 +30,7 @@ fn parse_and_gen(entry: &Path) { .expect("failed to parse input as a module"); let mut code = vec![]; - let mut srcmap = Vec::new(); + let mut srcmap = vec![]; { let mut emitter = Emitter { @@ -57,7 +56,7 @@ fn parse_and_gen(entry: &Path) { .expect("failed to process a module"); } -/// Usage: ./scripts/instruments path/to/input/file +/// Usage: ./scripts/instruements path/to/input/file fn main() { let main_file = env::args().nth(1).unwrap(); diff --git a/crates/swc_ecma_codegen/src/tests.rs b/crates/swc_ecma_codegen/src/tests.rs index a86ba42ffa42..3a89dd94d4fa 100644 --- a/crates/swc_ecma_codegen/src/tests.rs +++ b/crates/swc_ecma_codegen/src/tests.rs @@ -1,6 +1,5 @@ use std::path::PathBuf; -use swc_allocator::vec::Vec; use swc_common::{comments::SingleThreadedComments, FileName, SourceMap}; use swc_ecma_parser; use swc_ecma_testing::{exec_node_js, JsExecOptions}; @@ -45,11 +44,11 @@ impl Builder { where F: for<'aa> FnOnce(&mut Emitter<'aa, Box<(dyn WriteJs + 'aa)>, SourceMap>), { - let mut buf = Vec::new(); + let mut buf = vec![]; self.with(src, &mut buf, op); - String::from_utf8_lossy(&buf).into_owned() + String::from_utf8(buf).unwrap() } } 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 055317a54feb..e21389cc474f 100644 --- a/crates/swc_ecma_codegen/src/text_writer/basic_impl.rs +++ b/crates/swc_ecma_codegen/src/text_writer/basic_impl.rs @@ -1,7 +1,6 @@ use std::io::Write; use rustc_hash::FxHashSet; -use swc_allocator::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 73ffa99d9767..1fdaec759198 100644 --- a/crates/swc_ecma_codegen/tests/sourcemap.rs +++ b/crates/swc_ecma_codegen/tests/sourcemap.rs @@ -3,7 +3,6 @@ use std::{fs::read_to_string, path::PathBuf}; use base64::prelude::{Engine, BASE64_STANDARD}; use rustc_hash::FxHashSet; use sourcemap::SourceMap; -use swc_allocator::vec::Vec; use swc_common::{comments::SingleThreadedComments, source_map::SourceMapGenConfig}; use swc_ecma_ast::EsVersion; use swc_ecma_codegen::{text_writer::WriteJs, Emitter}; @@ -316,7 +315,7 @@ fn identity(entry: PathBuf) { Some(&comments), ); let mut parser: Parser = Parser::new_from(lexer); - let mut src_map = Vec::new(); + let mut src_map = vec![]; { let mut wr = Box::new(swc_ecma_codegen::text_writer::JsWriter::new( diff --git a/crates/swc_ecma_transforms_base/Cargo.toml b/crates/swc_ecma_transforms_base/Cargo.toml index b13d09ff43b6..e9ca9dcb9fd5 100644 --- a/crates/swc_ecma_transforms_base/Cargo.toml +++ b/crates/swc_ecma_transforms_base/Cargo.toml @@ -34,7 +34,6 @@ swc_ecma_ast = { version = "0.116.0", path = "../swc_ecma_ast" } swc_ecma_parser = { version = "0.147.0", path = "../swc_ecma_parser" } swc_ecma_utils = { version = "0.132.0", path = "../swc_ecma_utils" } swc_ecma_visit = { version = "0.102.0", path = "../swc_ecma_visit" } -swc_allocator = { version = "0.1.5", path = "../swc_allocator", default-features = false } [dev-dependencies] codspeed-criterion-compat = { workspace = true } diff --git a/crates/swc_ecma_transforms_react/Cargo.toml b/crates/swc_ecma_transforms_react/Cargo.toml index 9b26c8345749..af359148defc 100644 --- a/crates/swc_ecma_transforms_react/Cargo.toml +++ b/crates/swc_ecma_transforms_react/Cargo.toml @@ -27,7 +27,6 @@ serde = { workspace = true, features = ["derive"], optional = true } sha1 = { workspace = true } string_enum = { version = "0.4.4", path = "../string_enum" } -swc_allocator = { version = "0.1.5", path = "../swc_allocator", default-features = false } swc_atoms = { version = "0.6.5", path = "../swc_atoms" } swc_common = { version = "0.35.0", path = "../swc_common" } swc_config = { version = "0.1.13", path = "../swc_config" } 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 4ae2ae269867..b7aeb94bf43f 100644 --- a/crates/swc_ecma_transforms_react/src/pure_annotations/tests.rs +++ b/crates/swc_ecma_transforms_react/src/pure_annotations/tests.rs @@ -1,4 +1,3 @@ -use swc_allocator::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}; @@ -41,8 +40,8 @@ fn emit( comments: Lrc, program: &Module, ) -> String { - let mut src_map_buf = Vec::new(); - let mut buf = std::vec::Vec::new(); + let mut src_map_buf = vec![]; + let mut buf = vec![]; { let writer = Box::new(JsWriter::new( source_map.clone(), diff --git a/crates/swc_fast_ts_strip/Cargo.toml b/crates/swc_fast_ts_strip/Cargo.toml index 60ce710bc4d5..b3d7f56c8000 100644 --- a/crates/swc_fast_ts_strip/Cargo.toml +++ b/crates/swc_fast_ts_strip/Cargo.toml @@ -13,7 +13,6 @@ version = "0.3.0" [dependencies] anyhow = { workspace = true } serde = { workspace = true, features = ["derive"] } -swc_allocator = { version = "0.1.5", path = "../swc_allocator", default-features = false } swc_common = { version = "0.35.0", path = "../swc_common", features = [ "sourcemap", diff --git a/crates/swc_fast_ts_strip/src/lib.rs b/crates/swc_fast_ts_strip/src/lib.rs index 92e2b78c9e90..f2ea8400834b 100644 --- a/crates/swc_fast_ts_strip/src/lib.rs +++ b/crates/swc_fast_ts_strip/src/lib.rs @@ -241,7 +241,7 @@ pub fn operate( let mut src = vec![]; let mut src_map_buf = if options.source_map { - Some(swc_allocator::vec::Vec::new()) + Some(vec![]) } else { None };