Repository navigation
Keep parsing and analysis linear on long import lists, wrapped expressions and late module syntax - #1330
Open
tolgaergin wants to merge 4 commits into
Open
Keep parsing and analysis linear on long import lists, wrapped expressions and late module syntax#1330tolgaergin wants to merge 4 commits into
tolgaergin wants to merge 4 commits into
Conversation
…sions and late module syntax Some work in oxc's parser and in lpm-security's rules grew with what came before it rather than with the bytes read, so neither the speculation budget nor the stack floor bounded it. Measured in release builds: - Resolving exports searched every import entry for each local export: 40,000 of each took 3 s. The import entries are indexed by local name once there are more than 16, keeping the first entry for each name. - A /*#__PURE__*/ comment before nested parentheses walked every parenthesis inside them: 40,000 levels took 1.1 s. The walk for the last comment is remembered, and a walk that reaches where it started takes its answer. - When module syntax is found late, each statement that starts with `await` is parsed again, including those an earlier statement parsed again had taken in: 8,000 lines took 0.5 s and 1 GB, and the program kept overlapping statements. Those candidates are skipped now, and covered statements dropped. - The rules read through parentheses and TypeScript wrappers, and read a binding's initializer again for every reference to it. lpm-security now reads a source in which an expression sits in more than 32 such wrappers directly without parsing it, as it does one over its other budgets. Across 370,776 files of a local package store, real code wraps at most 5 deep. The parser also checks both of its limits with one comparison per token: the lexer's stop_below starts at the stack floor and goes past every address once either limit is reached. On 300 MB of real files the patched parser is about 2% slower than the published crate, where it was 2–3% slower. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…acks, and scope wrapper runs Review of the previous commit: - A pure comment inside a computed key at each level replaced the one remembered walk, so outer comments walked the whole chain again: 30,000 levels took 6.8 s in a debug build. Every walk's start is remembered now, so no node is walked twice. - A statement parsed again as a module could end inside a statement the first parse read, as `await\nawait /x/` ends inside the script's `await / x / foo()`, and dropping covered statements then lost `foo();`, as upstream's reparse also did. The reparse now parses on to the end of a statement the first parse read, and the module record keeps a dynamic import or `import.meta` recorded again only once. - A source over the wrapper bound was read as raw text, so a string holding `eval(y)` became an evaluation finding. It keeps the masked text now and only skips the rules that read through wrappers. - A run of wrappers continued into a TypeScript type's computed key. It continues only into the expression a wrapper wraps, or the last expression of a sequence. - The import index is built only when there is a local export to look up. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…iming test A statement parsed again parses on to the end of one the first parse read, so it covers every statement it overlaps. Should a parse again stop early on an error, a statement that reaches past it now stays instead of being dropped: an overlap loses no code. The AST test now also covers `await\nlet\nx = eval(y)`, whose parse again ends inside the script's `let x = eval(y)`. The top-level-await timing test parses 10,000 lines, so it fails without the fix in release builds too, not only in debug ones. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…every wrapper kind counts A statement parsed again as a module can end inside one its script reading took in, as `await / a; x = /;0/ + eval(y);` and `await /a/\neval(y)` do. Since the parse again goes on to the end of a statement the first parse read, the code after it is parsed again and analyzed; tests now cover both, through the AST and through lpm-security, which skips its text checks for evaluation when the parse is complete. The wrapper bound's tests cover each kind the rules read through: `as`, `satisfies`, `<T>`, `!` and an instantiation, besides parentheses and sequences. LPM-PATCH.md and the state field say why an address in pure_walks can't name another node. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tolgaergin
marked this pull request as ready for review
November 25, 2026 03:39
This branch has not been deployed
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.
Acts on the Gemini 4 Neon performance review of this stack. Each item below is work that grows with what came before it rather than with the bytes read, so neither the speculation budget nor the stack floor bounded it. Most of it predates the oxc 0.160 update.
Parser (
vendor/oxc_parser, described inLPM-PATCH.md)import{a,a,…}from'x';export{b,b,…};, 40,000 eachresolve_export_entriesindexes the import entries by local name once there are more than 16 and a local export to look up, keeping the first entry for each name as the search did./*#__PURE__*/(nested 40,000 deep, also with a pure-annotated computed key at each levelParserState::pure_walksremembers where each pure comment's walk started and what it found; a walk that reaches one takes its answer, so no node is walked twice.awaitbeforeexport {}in an unambiguous sourcereparse_potential_top_level_awaitsskips the candidates an earlier statement parsed again took in.Fixes to the top-level-await reparse. A statement parsed again as a module can end inside one its script reading took in. Upstream then lost the rest from the AST while keeping its tokens; Node runs that code:
await /a/\neval(y)losteval(y), which the script read as part ofawait / a / eval(y).await / a; x = /;0/ + eval(y);lost0/ + eval(y).Now:
import.metarecorded again only once.The parser also checks both of its limits with one comparison per token. The lexer's
stop_belowstarts at the stack floor and goes past every address once either limit is reached.Parse speed over 300 MB of local package-store files (release, full LTO, interleaved runs, medians; statement counts identical across all three):
lpm-securityparses* The published crate has neither option, so it parses without them.
lpm-securityThe rules read through parentheses and TypeScript wrappers (
as,satisfies,!,<T>, instantiations), and through sequences via their last expression. They also read a binding's initializer again for each reference to it. An initializer wrapped 10,000 deep and referenced 20,000 times took 2.8 s in a debug build, about 1 s per pass in release.syntax.rsnow measures, during the literal visit it already makes, the longest run of such wrappers that an expression sits in directly. A run continues only into the expression a wrapper wraps, or into a sequence's last expression, never into a type annotation.MAX_WRAPPER_RUN(32) keeps its comments and literals masked for the pattern checks, but the rules that read through wrappers don't run on it.lpm auditreports the package's coverage as partial (unsupported_source_syntax) andlpm queryrefuses an incomplete analysis.Tests
syntax.rs), each failing before its fix:exports_of_many_imported_names_resolve_in_linear_time;pure_comments_on_nested_parentheses_apply_in_linear_time, both shapes;top_level_awaits_parsed_again_as_a_module_take_linear_time, 10,000 lines, so it also fails in release builds.a_top_level_await_parsed_again_replaces_the_statements_it_takes_incovers whole statements,foo();,let, and the twoevalsources above.a_top_level_await_parsed_again_records_its_dynamic_import_once.pure_comments_on_nested_wrappers_mark_the_call_inside_them, which passes with and without the cache.mod.rs):code_after_a_top_level_await_parsed_again_is_analyzedchecks that theevalsources are complete and report evaluation; it fails without the reparse change.expressions_in_more_wrappers_than_real_code_has_are_read_without_parsing_in_linear_time.expressions_in_as_many_wrappers_as_real_code_could_have_are_parsedpins 32 against 33 for every wrapper kind, the sequence rule, and type annotations.a_source_in_too_many_wrappers_keeps_its_comments_and_literals_masked.Review
Fable 5.2, Sol 6.2 and Opus 5.5 reviewed the first commit. Every finding was verified and fixed test-first in the commits after it:
Checks run locally (macOS)
cargo clippy --workspace --all-targets --locked -- -D warnings: clean.cargo fmt --check: clean.cargo test -p lpm-security: 864 pass.cargo test -p lpm-runner: 652 pass. Twodev_endpointtests that bind real ports failed once under load; they passed in three reruns, and this PR doesn't touch them.lpm-stack-floor.patchapplied to the published 0.160.0 crate reproducesvendor/oxc_parser.🤖 Generated with Claude Code