Repository navigation
perf: answer isRecording() from a field once self-analysis is done - #2271
Merged
cdietrich merged 3 commits intoNov 18, 2026
Merged
Conversation
The parser checks isRecording() on every token and rule call. Chevrotain only records while finalize() runs its self-analysis, so remember when that is done and stop asking the Chevrotain wrapper afterwards. Before and during finalize() the wrapper is still asked; a repeated finalize() resets the field first. Fixes eclipse-langium#2266 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XkvVhAAk5NRLH75qMHMc3m
…() asking the wrapper Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XkvVhAAk5NRLH75qMHMc3m
Contributor
Author
|
Rough benchmark numbers for this branch vs.
No measurable effect in this benchmark: the difference is within run-to-run noise. Consistent with the description, it's a small gain at best, and it doesn't change allocation. 🤖 Generated with Claude Code |
msujew
reviewed
Nov 17, 2026
… suite As suggested in review: rule bodies only run while Chevrotain records the grammar during the self-analysis in finalize(), or while parsing afterwards, so `!selfAnalysisDone` alone answers isRecording() and the wrapper's IS_RECORDING getter is no longer needed. Subclasses that override finalize() must call super.finalize(). The dedicated test suite is removed: the existing parser tests fail broadly if isRecording() answers wrongly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XkvVhAAk5NRLH75qMHMc3m
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.
Fixes #2266
The parser checks
isRecording()on every token and rule call (9 call sites inlangium-parser.ts, 2 inparser-builder-base.ts), and each check asked the Chevrotain wrapper forIS_RECORDING. Chevrotain only records whileperformSelfAnalysis()runs, which Langium calls infinalize(). Afterwards the answer is alwaysfalse.AbstractLangiumParsernow remembers whetherfinalize()has completed the self-analysis and answersisRecording()from that field alone (!this.selfAnalysisDone); the wrapper'sIS_RECORDINGgetter is removed. This is equivalent because every caller ofisRecording()sits in a rule body or parser action, and rule bodies only run while Chevrotain records the grammar duringfinalize(), or while parsing afterwards. A repeatedfinalize()resets the field first, so it records again. Subclasses that overridefinalize()must callsuper.finalize().No dedicated tests: the existing parser tests cover
isRecording()broadly. Making it alwaysfalse, ortrueafterfinalize(), fails 408 of them.Effect, measured on Langium 4.4.2 with a large DSL (details in #2266): about −2 % CPU for building a workspace and −1 to −4 % for parsing single documents, no change in allocation. It's a small gain; the rough numbers for this branch are in the comment below.
🤖 Generated with Claude Code
https://claude.ai/code/session_01XkvVhAAk5NRLH75qMHMc3m