Repository navigation
build: optimize Boa in debug builds so stylesheets fit a test stack - #976
Merged
Merged
Conversation
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 Report✅ All modified and coverable lines are covered by tests.
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
debug 빌드에서 vanilla-extract
.css.ts의style()안에g(f(1)).d(3).toString()처럼 체인 호출 안에 호출이 들어가면 테스트 스레드 기본 스택(2 MiB)이 넘쳤습니다(#972에서 발견). 원인을 찾았고, debug/test 빌드에서만 Boa를opt-level = 1로 컴파일해서 고쳤습니다.원인 조사
extract_source,evaluate_located,execute_located는 수 KB만 씁니다.context.eval()안에서 납니다.__at의authored_call등)이 아직 한 번도 실행되지 않았습니다.Script::parse만 해도 2 MiB 스레드에서 overflow가 납니다.__at(loc, name, __read_site(n, () => …))와 read-site 래퍼를 씌웁니다. 그래서 호출 4개짜리 체인이 괄호 17단계와 arrow 함수 여러 개로 중첩됩니다.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을 추가했습니다.stylesheet_stack_testswidth를 확인합니다.범위 밖 / 남은 것
__vanilla_extract__.__at(...)호출의 인자까지 read-site로 감싸서 중첩이 불필요하게 깊어집니다. 이것을 줄이면 release에서도 여유가 생기겠지만, 에러 위치 매핑에 영향이 있어서 이번에는 손대지 않았습니다.겹치는 PR
compiled()의stack_size(8 << 20))를 이 PR 뒤에 제거할 수 있습니다.Refs #683
Test plan
stylesheet_stack_tests가STATUS_STACK_OVERFLOW로 실패하는 것 확인 (Cargo.toml변경을 되돌렸을 때도 같음)cargo test -p extractor --tests -j 2전체 통과cargo clippy -p extractor --all-targets -- -D warnings,cargo fmt --all🤖 Generated with Claude Code