Repository navigation
perf: build AST node paths as flat strings - #2282
Merged
Merged
Conversation
`DefaultAstNodeLocator.getAstNodePath` built a path by concatenating each segment onto its container's path. In V8 every `+` creates a cons string, a tree node that points at its two halves, so a path of depth d stays a tree of about 2·d nodes that keeps all its segment strings alive. Paths are retained for as long as the index holds them: `AstNodeDescription.path` for every exported symbol, and `sourcePath`/`targetPath` of every `ReferenceDescription`. Collect the segments and `join` them once, which yields one flat string and leaves the segments to be collected. The paths are the same as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Closes #2281.
DefaultAstNodeLocator.getAstNodePathconcatenated each segment onto its container's path, so every path was a V8 cons-string tree of about 2·d nodes that kept all its segment strings alive. The index retains these paths (AstNodeDescription.path,ReferenceDescription.sourcePath/targetPath) for as long as the documents live.Collect the segments and
jointhem once. That yields one flat string per path and leaves the segments to be collected. The paths are the same as before. On a large DSL workspace (11,944 documents, Node 24) the heap after a full build drops from 1,030.5 to 987.4 MiB (−4.2 %); details in #2281.The loop no longer calls
getAstNodePathfor the container;getPathSegmentis still called for every segment, so overrides of it keep working.Tests: a new test checks the empty path of the root and that the path of every node of a nested grammar resolves back to that node; the existing tests pin the exact path strings.
vitest run packages/langium: 1,281 passed.🤖 Generated with Claude Code