Skip to content

perf: build AST node paths as flat strings - #2282

Merged
msujew merged 1 commit into
mainfrom
perf/ast-node-path-join
Nov 19, 2026
Merged

msujew merged 1 commit into
mainfrom
perf/ast-node-path-join

Conversation

@cdietrich

@cdietrich cdietrich commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Closes #2281.

DefaultAstNodeLocator.getAstNodePath concatenated 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 join them 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 getAstNodePath for the container; getPathSegment is 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

`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>

@msujew msujew left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@msujew
msujew merged commit 36a31d7 into main Nov 19, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Perf: DefaultAstNodeLocator.getAstNodePath builds paths as cons-string trees that stay retained in the index

2 participants