Make grammar immutable#469
Merged
lukemurray merged 3 commits intoEntityGraphQL:masterfrom Aug 23, 2025
Merged
Conversation
Contributor
Author
|
I also changed the benchmarks slightly to move the initialization code out of the hot path so the results only focus on what matters. And returned the resulting expression such that the compiler would not optimize the method as the result is not used (it is not but it's a best practice for BDN usage). |
Contributor
Author
|
Are the tests flaky? I don't even get the same failing ones locally. I can already see a problem due to timezones, but I don't get why the others are different. |
Collaborator
|
Thank you very much for this! Yes that 1 test fails sometimes. I need to track down why - it includes all the fields just a different order, which typing this out actually might make sense depending on how tests run and I should check it with regardless of order. |
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.
This is the flamegraph before the fix. I could see that all the time was spent in creating parse nodes and initializing their structures (ToDictionary, CharMap, ...). This is not normal, this should be done once. This meant that the parsers were begin constructed too often. The parser should be a singleton, unless some grammars vary in terms of syntax, but not behavior.
The solution is to incorporate the
ParseContextwhich is specific to each invocation. And the parser lambdas can use it. This way the parser can be static. I used a localInstancefield but I usually create my own static parser instance that I reuse. Totally fine how I did it here. Makes it more obvious for the future.