Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perform parser optimizations in production mode #1688

Merged
merged 3 commits into from
Sep 30, 2024

Conversation

msujew
Copy link
Member

@msujew msujew commented Sep 19, 2024

Closes #1687

Improves the production mode setting for the langium CLI. It's now generated into the language meta data and is used to skip validations and ignore ambiguity issues in the parser if activated.

This should improve the startup time of all grammars and is quite noticeable on larger grammars.

@msujew msujew added the parser Parser related issue label Sep 19, 2024
Copy link
Member

@aabounegm aabounegm left a comment

Choose a reason for hiding this comment

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

Looks good, but as I understand, this needs to be explicitly configured in langium-config.json, right?
Perhaps it is possible to add a default value in loadConfig like so?

config.mode ??= process.env.NODE_ENV ?? 'development';

Such that warnings would be present in dev mode (running with npm run langium:watch), but not in the production build

packages/langium-cli/src/generator/module-generator.ts Outdated Show resolved Hide resolved
packages/langium/src/languages/language-meta-data.ts Outdated Show resolved Hide resolved
@msujew
Copy link
Member Author

msujew commented Sep 19, 2024

@aabounegm Thanks for taking a look!

Looks good, but as I understand, this needs to be explicitly configured in langium-config.json, right?

You can also use the --mode=production CLI argument to switch between development and production mode. I'm not a big fan of using env variables for that.

@aabounegm
Copy link
Member

Ok that makes sense, I wasn't aware of the CLI option. In that case, maybe there should be an explicit --mode=production in the langium:generate scripts?

@msujew
Copy link
Member Author

msujew commented Sep 19, 2024

There already is:

"langium:generate:production": "langium generate --mode=production",

It's invoked before publishing the Langium artifacts.

@msujew msujew force-pushed the msujew/disable-parser-warnings branch 2 times, most recently from 76250a8 to 5547dab Compare September 19, 2024 11:44
@msujew msujew force-pushed the msujew/disable-parser-warnings branch from 5547dab to 0fd4151 Compare September 19, 2024 11:45
@aabounegm
Copy link
Member

Sorry, I meant in the template so that new projects would make use of it

@spoenemann
Copy link
Contributor

How would we handle this when we publish the npm packages and vscode extension? Shall we re-generate the grammar language with production mode before publishing?

Copy link
Contributor

@spoenemann spoenemann left a comment

Choose a reason for hiding this comment

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

Oh I see, that's what we already do:

npm run langium:generate:production --workspace=langium

It's a bit strange to change a generated file that is also in version control during the release process, but this is likely the most pragmatic solution for now.

@msujew msujew merged commit d71b47b into main Sep 30, 2024
5 checks passed
@msujew msujew deleted the msujew/disable-parser-warnings branch September 30, 2024 10:15
@msujew msujew added this to the v3.3.0 milestone Sep 30, 2024
@cdietrich
Copy link
Contributor

@msujew will there a preview/alpha available for this feature

@msujew
Copy link
Member Author

msujew commented Oct 1, 2024

@cdietrich I can release one after tomorrow's dev meeting. I'll let you know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
parser Parser related issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add an option to suppress Chevrotain warnings
4 participants