Skip to content

build: optimize Boa in debug builds so stylesheets fit a test stack - #976

Merged
owjs3901 merged 1 commit into
mainfrom
fix/stylesheet-eval-stack
Nov 15, 2026
Merged

owjs3901 merged 1 commit into
mainfrom
fix/stylesheet-eval-stack

Conversation

@owjs3901

Copy link
Copy Markdown
Contributor

Summary

debug 빌드에서 vanilla-extract .css.ts의 style() 안에 g(f(1)).d(3).toString()처럼 체인 호출 안에 호출이 들어가면 테스트 스레드 기본 스택(2 MiB)이 넘쳤습니다(#972에서 발견). 원인을 찾았고, debug/test 빌드에서만 Boa를 opt-level = 1로 컴파일해서 고쳤습니다.

원인 조사

  • 처음에는 extractor 자체의 재귀 평가(큰 enum을 프레임마다 들고 있는 함수)를 의심했습니다. 그런데 확인해 보니 extractor의 프레임은 원인이 아닙니다.
  • 임시 probe로 스택 주소를 찍어 보니 다음과 같았습니다.
    • extract_source, evaluate_located, execute_located는 수 KB만 씁니다.
    • overflow는 Boa context.eval() 안에서 납니다.
    • 그 시점에는 native 콜백(__at의 authored_call 등)이 아직 한 번도 실행되지 않았습니다.
  • 즉 Boa가 instrument된 스크립트를 parse/compile하는 단계에서 넘칩니다.
    • 원본 코드를 Boa로 그냥 평가하면 문제없습니다.
    • instrument된 1.7 kB 스크립트를 Script::parse만 해도 2 MiB 스레드에서 overflow가 납니다.
  • instrument는 authored 호출마다 __at(loc, name, __read_site(n, () => …))와 read-site 래퍼를 씌웁니다. 그래서 호출 4개짜리 체인이 괄호 17단계와 arrow 함수 여러 개로 중첩됩니다.
    • 최적화하지 않은 Boa의 recursive-descent parser와 bytecompiler는 이 중첩 한 단계마다 스택을 많이 씁니다.
  • boa_parser만 최적화하면 보고된 케이스는 통과합니다. 하지만 g(f(f(f(1)))).d(3).toString() 같은 더 깊은 체인은 여전히 넘쳤습니다(compile/VM 단계).
    • opt-level = 3은 inlining 때문에 오히려 프레임이 커져서 더 나빴습니다.

변경

  • 워크스페이스 Cargo.toml에 [profile.dev.package.{boa_parser,boa_engine,boa_ast}] opt-level = 1을 추가했습니다.
    • release/native/WASM 빌드와 배포 패키지는 바뀌지 않습니다.
    • 커버리지 측정 대상(우리 crate)도 바뀌지 않습니다.
  • 회귀 테스트 stylesheet_stack_tests
    • 기본 테스트 스레드에서 중첩 체인 4가지를 추출하고, 계산된 width를 확인합니다.
    • 이 변경을 빼면 overflow로 프로세스가 죽는 것을 확인했습니다.

범위 밖 / 남은 것

  • instrument가 synthetic __vanilla_extract__.__at(...) 호출의 인자까지 read-site로 감싸서 중첩이 불필요하게 깊어집니다. 이것을 줄이면 release에서도 여유가 생기겠지만, 에러 위치 매핑에 영향이 있어서 이번에는 손대지 않았습니다.
  • 아주 깊은 authored 중첩은 release에서도 결국 Boa 스택 한계에 닿을 수 있습니다. 이 PR은 debug 빌드 문제만 해결합니다.

겹치는 PR

Refs #683

Test plan

  • main에서 stylesheet_stack_tests가 STATUS_STACK_OVERFLOW로 실패하는 것 확인 (Cargo.toml 변경을 되돌렸을 때도 같음)
  • 변경 후 4개 케이스 통과
  • cargo test -p extractor --tests -j 2 전체 통과
  • cargo clippy -p extractor --all-targets -- -D warnings, cargo fmt --all
  • CI (tarpaulin은 dev 계열 profile을 쓰므로 같은 override가 적용됩니다)

🤖 Generated with Claude Code

A vanilla-extract stylesheet reading `g(f(1)).d(3).toString()` overflowed
the 2 MiB stack of a test thread in debug builds. The overflow happens
before any stylesheet code or native callback runs: Boa parses the
instrumented script, where each authored call is wrapped in read-site
and `__at` thunks, so a four-call chain nests 17 brackets plus arrows.
Unoptimized, Boa's recursive-descent parser and compiler use enough stack
per level to run out; parsing that 1.7 kB script alone with Boa
overflows. The extractor's own frames are not involved.

Debug and test builds now compile boa_parser, boa_engine and boa_ast at
opt-level 1. Release builds are unchanged. A test runs four nested
chained calls on the default test thread.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
libs/extractor/src/lib.rs 100.00% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@owjs3901
owjs3901 merged commit 8ce7fb5 into main Nov 15, 2026
27 checks passed
@owjs3901
owjs3901 deleted the fix/stylesheet-eval-stack branch November 15, 2026 22:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant