API: cache SourceFile text to heavily improve performance#4414
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves performance in the native-preview remote AST layer by caching SourceFile.text so repeated calls (e.g. from getTokenPosOfNode → getStart/getText) don’t repeatedly decode the source text from the string table.
Changes:
- Add a
__cachedTextfield and cache logic to the generatedRemoteNode.textgetter forSyntaxKind.SourceFile. - Update the generator (
_scripts/generate-encoder.ts) so the caching logic is consistently produced innode.generated.ts.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
_scripts/generate-encoder.ts |
Updates code generation for RemoteNode.text to include a SourceFile text cache. |
_packages/native-preview/src/api/node/node.generated.ts |
Generated output reflecting the new SourceFile text cache in RemoteNode.text. |
Member
|
This is a good optimization—could you put the cache on |
2c3aa11 to
e4d1662
Compare
andrewbranch
approved these changes
Jun 23, 2026
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.
When using
getTokenPosOfNodeon various nodes, each time SourceFile text is required causing huge performance issues. This is a minimal change to improve performance in such cases. I wonder though, whether such a cache shouldn't be on each Node. CC @andrewbranch