From 3b76ff69677ebe7ca37ea30b71b1a14967ce5b50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Thu, 4 Jul 2024 13:04:39 +0900 Subject: [PATCH 1/9] allow `-t memory` --- xtask/src/bench.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/xtask/src/bench.rs b/xtask/src/bench.rs index 38e57cc96c8c..851b9e42b6f1 100644 --- a/xtask/src/bench.rs +++ b/xtask/src/bench.rs @@ -15,6 +15,10 @@ pub(super) struct BenchCmd { #[clap(long)] debug: bool, + /// Template to use while instrumenting + #[clap(short = 't')] + template: Option, + #[clap(long)] no_lib: bool, @@ -50,7 +54,8 @@ impl BenchCmd { // ddt profile instruments cargo -t time let mut cmd = Command::new("ddt"); cmd.arg("profile").arg("instruments").arg("cargo"); - cmd.arg("-t").arg("time"); + cmd.arg("-t") + .arg(self.template.as_deref().unwrap_or("time")); if !self.debug { cmd.arg("--release"); From 4c4c54db7dc3df31f0401a9d9ebac36116fe839a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Thu, 4 Jul 2024 13:22:32 +0900 Subject: [PATCH 2/9] maybe_grow_default --- crates/swc_ecma_parser/src/lib.rs | 7 +++++++ crates/swc_ecma_parser/src/parser/stmt.rs | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/crates/swc_ecma_parser/src/lib.rs b/crates/swc_ecma_parser/src/lib.rs index 3d20d6f8684c..1cb9438a068f 100644 --- a/crates/swc_ecma_parser/src/lib.rs +++ b/crates/swc_ecma_parser/src/lib.rs @@ -534,3 +534,10 @@ fn maybe_grow R>(_red_zone: usize, _stack_size: usize, callbac fn maybe_grow R>(red_zone: usize, stack_size: usize, callback: F) -> R { stacker::maybe_grow(red_zone, stack_size, callback) } + +/// Calls `callback` with a larger stack size. +/// +/// `maybe_grow` with default values. +fn maybe_grow_default R>(callback: F) -> R { + maybe_grow(4 * 1024, 16 * 1024, callback) +} diff --git a/crates/swc_ecma_parser/src/parser/stmt.rs b/crates/swc_ecma_parser/src/parser/stmt.rs index 1b6cbcc000ee..984226322ce1 100644 --- a/crates/swc_ecma_parser/src/parser/stmt.rs +++ b/crates/swc_ecma_parser/src/parser/stmt.rs @@ -519,7 +519,7 @@ impl<'a, I: Tokens> Parser { let cons = { // Prevent stack overflow - crate::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { + crate::maybe_grow_default(|| { // Annex B if !self.ctx().strict && is!(self, "function") { // TODO: report error? @@ -552,7 +552,7 @@ impl<'a, I: Tokens> Parser { if !is!(self, "if") { // As we eat `else` above, we need to parse statement once. - let last = crate::maybe_grow(512 * 1024, 2 * 1024 * 1024, || { + let last = crate::maybe_grow_default(|| { let ctx = Context { ignore_else_clause: false, ..self.ctx() From 78e488247c75331ba11b2340e52d6b075ffa5f23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Thu, 4 Jul 2024 13:22:46 +0900 Subject: [PATCH 3/9] CI --- .github/workflows/CI.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index ef97a38f6361..21a05720d347 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -14,8 +14,6 @@ env: DIFF: 0 # For faster CI RUST_LOG: "off" - # https://github.com/swc-project/swc/pull/3742 - RUST_MIN_STACK: 4194304 # https://github.com/actions/setup-node/issues/899#issuecomment-1819151595 SKIP_YARN_COREPACK_CHECK: 1 From 270c0b84fbb5a2c5c9b21e84939a87022ed31192 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Thu, 4 Jul 2024 13:23:56 +0900 Subject: [PATCH 4/9] Reduce --- crates/swc_ecma_utils/src/stack_size.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/swc_ecma_utils/src/stack_size.rs b/crates/swc_ecma_utils/src/stack_size.rs index d05d03cdaa9e..304e75b5c72a 100644 --- a/crates/swc_ecma_utils/src/stack_size.rs +++ b/crates/swc_ecma_utils/src/stack_size.rs @@ -25,5 +25,5 @@ pub fn maybe_grow R>(red_zone: usize, stack_size: usize, callb /// /// `maybe_grow` with default values. pub fn maybe_grow_default R>(callback: F) -> R { - maybe_grow(4 * 1024, 16 * 1024, callback) + maybe_grow(1024, 4 * 1024, callback) } From 3ebbc57afd6f009b457a6d398e5eb7b3cc30fa64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Thu, 4 Jul 2024 13:24:04 +0900 Subject: [PATCH 5/9] Reduce --- crates/swc_ecma_parser/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/swc_ecma_parser/src/lib.rs b/crates/swc_ecma_parser/src/lib.rs index 1cb9438a068f..94d859b26209 100644 --- a/crates/swc_ecma_parser/src/lib.rs +++ b/crates/swc_ecma_parser/src/lib.rs @@ -539,5 +539,5 @@ fn maybe_grow R>(red_zone: usize, stack_size: usize, callback: /// /// `maybe_grow` with default values. fn maybe_grow_default R>(callback: F) -> R { - maybe_grow(4 * 1024, 16 * 1024, callback) + maybe_grow(1024, 4 * 1024, callback) } From e0a5370c1e3b96b3b7e4ea37fe3eb137e2390ca6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Thu, 4 Jul 2024 13:29:31 +0900 Subject: [PATCH 6/9] Optimize --- crates/swc_ecma_parser/src/parser/stmt.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/swc_ecma_parser/src/parser/stmt.rs b/crates/swc_ecma_parser/src/parser/stmt.rs index 984226322ce1..04d4a2830b06 100644 --- a/crates/swc_ecma_parser/src/parser/stmt.rs +++ b/crates/swc_ecma_parser/src/parser/stmt.rs @@ -519,7 +519,7 @@ impl<'a, I: Tokens> Parser { let cons = { // Prevent stack overflow - crate::maybe_grow_default(|| { + crate::maybe_grow(128 * 1024, 512 * 1024, || { // Annex B if !self.ctx().strict && is!(self, "function") { // TODO: report error? From eba068b3d23f16b1b9efe8dfabc0edfb9fc3b5bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Thu, 4 Jul 2024 13:31:41 +0900 Subject: [PATCH 7/9] Remove unneseccary calls --- crates/swc_ecma_parser/src/lib.rs | 7 ------- crates/swc_ecma_parser/src/parser/stmt.rs | 14 ++++++-------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/crates/swc_ecma_parser/src/lib.rs b/crates/swc_ecma_parser/src/lib.rs index 94d859b26209..3d20d6f8684c 100644 --- a/crates/swc_ecma_parser/src/lib.rs +++ b/crates/swc_ecma_parser/src/lib.rs @@ -534,10 +534,3 @@ fn maybe_grow R>(_red_zone: usize, _stack_size: usize, callbac fn maybe_grow R>(red_zone: usize, stack_size: usize, callback: F) -> R { stacker::maybe_grow(red_zone, stack_size, callback) } - -/// Calls `callback` with a larger stack size. -/// -/// `maybe_grow` with default values. -fn maybe_grow_default R>(callback: F) -> R { - maybe_grow(1024, 4 * 1024, callback) -} diff --git a/crates/swc_ecma_parser/src/parser/stmt.rs b/crates/swc_ecma_parser/src/parser/stmt.rs index 04d4a2830b06..a52e80f82d11 100644 --- a/crates/swc_ecma_parser/src/parser/stmt.rs +++ b/crates/swc_ecma_parser/src/parser/stmt.rs @@ -551,15 +551,13 @@ impl<'a, I: Tokens> Parser { } if !is!(self, "if") { - // As we eat `else` above, we need to parse statement once. - let last = crate::maybe_grow_default(|| { - let ctx = Context { - ignore_else_clause: false, - ..self.ctx() - }; + let ctx = Context { + ignore_else_clause: false, + ..self.ctx() + }; - self.with_ctx(ctx).parse_stmt(false) - })?; + // As we eat `else` above, we need to parse statement once. + let last = self.with_ctx(ctx).parse_stmt(false)?; break Some(last); } From c4985153358696573e8b89a284b4c7044f962e03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Thu, 4 Jul 2024 13:42:37 +0900 Subject: [PATCH 8/9] linux --- crates/swc_ecma_utils/src/stack_size.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/swc_ecma_utils/src/stack_size.rs b/crates/swc_ecma_utils/src/stack_size.rs index 304e75b5c72a..5841529688a6 100644 --- a/crates/swc_ecma_utils/src/stack_size.rs +++ b/crates/swc_ecma_utils/src/stack_size.rs @@ -25,5 +25,11 @@ pub fn maybe_grow R>(red_zone: usize, stack_size: usize, callb /// /// `maybe_grow` with default values. pub fn maybe_grow_default R>(callback: F) -> R { - maybe_grow(1024, 4 * 1024, callback) + let (red_zone, stack_size) = if cfg!(target_os = "linux") { + (4 * 1024, 16 * 1024) + } else { + (1024, 4 * 1024) + }; + + maybe_grow(red_zone, stack_size, callback) } From 01aeae1e082b7bb2e72139171af3721ccb7d4d48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Thu, 4 Jul 2024 13:42:46 +0900 Subject: [PATCH 9/9] Increase stack size --- crates/swc_ecma_parser/src/parser/stmt.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/swc_ecma_parser/src/parser/stmt.rs b/crates/swc_ecma_parser/src/parser/stmt.rs index a52e80f82d11..0a8b458ad6e9 100644 --- a/crates/swc_ecma_parser/src/parser/stmt.rs +++ b/crates/swc_ecma_parser/src/parser/stmt.rs @@ -519,7 +519,7 @@ impl<'a, I: Tokens> Parser { let cons = { // Prevent stack overflow - crate::maybe_grow(128 * 1024, 512 * 1024, || { + crate::maybe_grow(256 * 1024, 1024 * 1024, || { // Annex B if !self.ctx().strict && is!(self, "function") { // TODO: report error?