WIP: fix: avoid repeated Acorn location scans - #18586
Draft
jschaf wants to merge 1 commit into
Draft
Conversation
|
Install the latest version of pnpm add https://pkg.svelte.dev/svelte/c/d7acfb026d62655b59fffca01ef0ac8854fbe0dcOpen in Note This PR is from a fork. A maintainer must approve approve each commit before it can be built and installed. |
🦋 Changeset detectedLatest commit: d7acfb0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
NOTE: not ready for review yet. I'm using this to explore whether we should adjust Acorn's API in acornjs/acorn#1448.
Svelte parses JavaScript embedded in component markup by repeatedly starting Acorn at different offsets in the same source string. Acorn initializes each parser by scanning the source prefix to recover the starting line, so components with many expression or declaration tags accumulate approximately quadratic parsing work.
This is the behavior described upstream in acornjs/acorn#1448.
svelte.This preserves absolute offsets, AST locations, comments, diagnostics, and source-map behavior while avoiding the repeated prefix scan for normal LF/CRLF component sources.
Performance
The patch shows 5-9% faster full compilation with no output differences for Immich, Open WebUI, and Skeleton.
Large individual components benefited substantially:
Measured on macOS arm64 with Node 26.3.1 and pnpm 10.4.0. Each result is the median of 9 measurements after 3 warmups.
Synthetic benchmark to show quadratic behavior
The fitted parse-time exponent drops from 1.53 to 0.84. At 4,096 expression tags, the parse phase is 12.9× faster.