-
-
Notifications
You must be signed in to change notification settings - Fork 233
perf: cache internal TS ASTs with incremental reparsing #2963
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| 'svelte2tsx': patch | ||
| 'svelte-language-server': patch | ||
| --- | ||
|
|
||
| perf: cache internal TypeScript ASTs with incremental reparsing | ||
|
|
||
| Use `ts.updateSourceFile()` instead of `ts.createSourceFile()` for repeated svelte2tsx calls on the same file. This reuses unchanged AST subtrees for ~27% faster svelte2tsx transforms on typical single-character edits. |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,5 +1,17 @@ | ||||||
| import ts from 'typescript'; | ||||||
|
|
||||||
| /** | ||||||
| * Cache for reusing internal TypeScript ASTs across svelte2tsx invocations. | ||||||
| * Pass the same cache object on repeated calls for the same file to enable | ||||||
| * incremental TS reparsing of script contents via `ts.updateSourceFile()`. | ||||||
| */ | ||||||
| export interface Svelte2TsxCache { | ||||||
| instanceScriptAst?: ts.SourceFile; | ||||||
| instanceScriptContent?: string; | ||||||
| moduleScriptAst?: ts.SourceFile; | ||||||
| moduleScriptContent?: string; | ||||||
| } | ||||||
|
|
||||||
| export interface SvelteCompiledToTsx { | ||||||
| code: string; | ||||||
| map: import("magic-string").SourceMap; | ||||||
|
|
@@ -95,6 +107,12 @@ export function svelte2tsx( | |||||
| * from the generated file location. | ||||||
| */ | ||||||
| rewriteExternalImports?: InternalHelpers.RewriteExternalImportsConfig; | ||||||
| /** | ||||||
| * Optional cache for reusing internal TypeScript ASTs across invocations. | ||||||
| * Pass the same object for repeated calls on the same file to enable | ||||||
| * incremental TS reparsing (~2x faster script parsing). | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
We shouldn't add this claim here. There are too many variables that affect the number. It doesn't make sense to add it as a documentation. |
||||||
| */ | ||||||
| cache?: Svelte2TsxCache; | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we don't need a concrete type here. It can be a |
||||||
| } | ||||||
| ): SvelteCompiledToTsx | ||||||
|
|
||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| export { svelte2tsx } from './svelte2tsx'; | ||
| export type { Svelte2TsxCache } from './svelte2tsx'; | ||
| export { emitDts } from './emitDts'; | ||
| export { internalHelpers } from './helpers'; |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file should not have any top-level state. You can put it as a field for
GlobalSnapshotsManager. This also needs to be aFileMapfor path case-sensitivity.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or a field in
Document, so we don't need a map, and it'll be cleared when the document is removed.