Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(es): Reduce allocations for dynamic stacks #9133

Merged
merged 10 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 7 additions & 9 deletions crates/swc_ecma_parser/src/parser/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ impl<'a, I: Tokens> Parser<I> {

let cons = {
// Prevent stack overflow
crate::maybe_grow(512 * 1024, 2 * 1024 * 1024, || {
crate::maybe_grow(256 * 1024, 1024 * 1024, || {
// Annex B
if !self.ctx().strict && is!(self, "function") {
// TODO: report error?
Expand Down Expand Up @@ -551,15 +551,13 @@ impl<'a, I: Tokens> Parser<I> {
}

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 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);
}

Expand Down
8 changes: 7 additions & 1 deletion crates/swc_ecma_utils/src/stack_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,11 @@ pub fn maybe_grow<R, F: FnOnce() -> R>(red_zone: usize, stack_size: usize, callb
///
/// `maybe_grow` with default values.
pub fn maybe_grow_default<R, F: FnOnce() -> R>(callback: F) -> R {
maybe_grow(4 * 1024, 16 * 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)
}
7 changes: 6 additions & 1 deletion xtask/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ pub(super) struct BenchCmd {
#[clap(long)]
debug: bool,

/// Template to use while instrumenting
#[clap(short = 't')]
template: Option<String>,

#[clap(long)]
no_lib: bool,

Expand Down Expand Up @@ -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");
Expand Down
Loading