perf(parser): guard arrow and conditional parsing (#28305)

Gate arrow and conditional parsing on tokens that can start those
constructs.

Native parse time versus parent: 1.5% lower with fresh arenas, 1.5%
lower with reuse (geometric mean, 12 files, arm64 macOS; 3 rounds × 100
samples).

Validated existing Rust/Node suites, parser/ESTree/token conformance,
allocation snapshots, and x86 compilation. AI-assisted implementation.

Depends on #28304.
This commit is contained in:
Boshen authored and GitHub committed 2026-10-29 16:30:20 +08:00
1 parent 36669393e7
commit 6cf5b1af9b
1 file changed
+5 -2
+5 -2
View File
@@ -1604,8 +1604,11 @@ impl<'a, C: Config> ParserImpl<'a, C> {
);
}
let mut expr =
self.parse_conditional_expression_rest(start, lhs, allow_return_type_in_arrow_function);
let mut expr = if self.at(Kind::Question) {
self.parse_conditional_expression_rest(start, lhs, allow_return_type_in_arrow_function)
} else {
lhs
};
if let Some(comments) = no_side_effects_comments {
self.apply_no_side_effects_comments_to_function(comments, &mut expr);