-
-
Notifications
You must be signed in to change notification settings - Fork 67
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
[.NET] Improved parsing time #336
Conversation
…or for System.Text.Json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good in general.
Just one question: is the optimization you had both in the parser and the ast builder that flattens the error handling wrapper method to try-catch everywhere counts a lot in perf? I understand that crating and invoking a delegate is more costly, but copy-pasting the same error handling code everywhere is pretty error-prone. That's the only change that somehow hurts me more. Would the numbers be very different without that one?
No problem. 🙂
Without it, Regarding error handling: |
@obligaron Thx for the measure. Yes, this is significant enough to keep. |
🤔 What's changed?
I have optimised the gherkin parser for better performance. This was done by avoiding string culture sensitive comparisons, (string) allocations and other optimisations (see commits for details).
For the
very_long.feature
this adds up to 3x to 7x improved parsing speed (depending on the .NET runtime used).Also added a BenchmarkDotNet project to measure the performance improvements (for now and in the future).
Setup:
Results before:
Results after:
⚡️ What's your motivation?
Investigated SourceCodeGenerator for .NET and gherkin parser speed was one part where much of the time was spent. Also gherkin parser speed is relevant for user interactions (IDE editing of future files) and general compilation speed in .NET.
I hope this helps to make gherkin even better. 🙂
🏷️ What kind of change is this?
♻️ Anything particular you want feedback on?
I changed some parts of the parsing to string ordinal comparison. string ordinal comparison was already used in a lot of places. So I don't think this is a hard breaking change. But I wanted to highlight it anyway (here and in the changelog).
Another thing is that I removed a Mono workaround that was probably no longer needed (regarding `string.StartsWith') that showed up during profiling.
📋 Checklist: