POC: Ast Merging and Scoped Cache Invalidation#2980
Draft
POC: Ast Merging and Scoped Cache Invalidation#2980
Conversation
77510cd to
e6c05fa
Compare
Experimenting with merging ASTs to preserve the object IDs of the nodes which might help with far more efficient caching techniques.
e6c05fa to
bc42d76
Compare
dantleech
commented
Dec 6, 2025
dantleech
commented
Dec 6, 2025
dantleech
commented
Dec 7, 2025
|
|
||
| if ($node2Child instanceof Node) { | ||
| // recurse on the listed node: | ||
| $this->doMerge($node1Child, $node2Child); |
dantleech
commented
Dec 7, 2025
| { | ||
| $source = $this->fileSource1; | ||
| $source->fileContents = TextEdits::one($edit)->apply($source->getFileContents()); | ||
| self::reindex($this->fileSource1); |
Collaborator
Author
There was a problem hiding this comment.
note that depending on the number of edits this can probably done far more efficiently by creating a TextEdits collection and applying them all and reindexingt once after updating the AST.
dantleech
commented
Dec 7, 2025
|
|
||
| private function copyNode(Node|Token $node): Node|Token | ||
| { | ||
| return $node; |
Collaborator
Author
There was a problem hiding this comment.
here to abstract the place where we could deep_copy the node, but performance wise we're probably happy to corrupt the second AST,
dantleech
commented
Dec 7, 2025
| return parent::parseSourceFile($source); | ||
| } | ||
|
|
||
| if (!isset($this->documents[$uri])) { |
Collaborator
Author
There was a problem hiding this comment.
we should probably, for now, use a Ttl caching mechanism, but should use the #2882
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.
Experimenting with merging ASTs to preserve the object IDs of the nodes which might help with far more efficient caching techniques.
The idea would be that the revised AST (e.g. afer user has made a text edit) is merged with the previous one. This means that unchanged nodes would not be replaced and so we are then able to cache by the nodes by their object ID over multiple requests - this is something simulates the behavior of an incremental parser (and the parser is absolutely not the bottleneck currently).
The other part of this would be scoped cache invalidation, so - given that the user changes some text within a scoped area (e.g. a method block) we would only invalidate the nodes within that block and not those in the rest of the document (as we mostly do currently). This would have a dramatic impact on performance in large files.