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

[.NET] Avoid allocation and improve parsing time #344

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

obligaron
Copy link
Contributor

🤔 What's changed?

This PR optimises allocations and speed by

  • changing some types from class to struct
  • removed/deferred some string trimming in GherkinLine
  • change some yield return methods to explicit struct enumerators (no allocations & can be inlined)
  • replaced arrays with IEnumerable so that List can be used, this avoids re-creating and coping with explicitly sized arrays

Results before:

Method Runtime FeatureFile Mean Error StdDev Gen0 Gen1 Allocated
Parser .NET 8.0 tags.feature 23.01 μs 0.440 μs 0.556 μs 2.9297 0.1221 49.04 KB
ParserReuse .NET 8.0 tags.feature 15.49 μs 0.215 μs 0.201 μs 2.5024 0.0916 41.18 KB
Parser .NET Framework 4.8.1 tags.feature 31.99 μs 0.613 μs 0.656 μs 9.2773 0.4272 57.32 KB
ParserReuse .NET Framework 4.8.1 tags.feature 23.45 μs 0.105 μs 0.088 μs 7.3853 0.2747 45.45 KB
Parser .NET 8.0 very_long.feature 565.50 μs 5.492 μs 5.138 μs 95.7031 54.6875 1568.74 KB
ParserReuse .NET 8.0 very_long.feature 546.43 μs 10.785 μs 10.088 μs 94.7266 47.8516 1558.77 KB
Parser .NET Framework 4.8.1 very_long.feature 931.86 μs 5.545 μs 5.187 μs 261.7188 96.6797 1610.54 KB
ParserReuse .NET Framework 4.8.1 very_long.feature 896.85 μs 2.761 μs 2.447 μs 259.7656 100.5859 1596.55 KB

Results after:

Method Runtime FeatureFile Mean Error StdDev Gen0 Gen1 Allocated
Parser .NET 8.0 tags.feature 13.443 μs 0.0661 μs 0.0618 μs 1.5869 - 26.76 KB
ParserReuse .NET 8.0 tags.feature 7.682 μs 0.0559 μs 0.0466 μs 1.1520 0.0305 18.86 KB
Parser .NET Framework 4.8.1 tags.feature 20.678 μs 0.0940 μs 0.0879 μs 5.2185 0.2136 32.13 KB
ParserReuse .NET Framework 4.8.1 tags.feature 13.165 μs 0.0836 μs 0.0782 μs 3.2806 0.1068 20.21 KB
Parser .NET 8.0 very_long.feature 295.813 μs 3.1228 μs 2.6077 μs 49.8047 30.2734 816.38 KB
ParserReuse .NET 8.0 very_long.feature 288.504 μs 0.9828 μs 0.8713 μs 49.3164 25.3906 806.37 KB
Parser .NET Framework 4.8.1 very_long.feature 564.142 μs 3.3668 μs 3.1493 μs 138.6719 54.6875 853.5 KB
ParserReuse .NET Framework 4.8.1 very_long.feature 540.853 μs 3.3997 μs 3.1801 μs 135.7422 45.8984 839.47 KB

⚡️ What's your motivation?

This reduces parsing time by ~45% and allocations by ~45%.

🏷️ What kind of change is this?

  • 🏦 Refactoring/debt/DX (improvement to code design, tooling, etc. without changing behaviour)
  • 💥 Breaking change (incompatible changes to the API)

♻️ Anything particular you want feedback on?

The removed IGherkinLine interface is used in the Reqnroll VisualStudio plugin (I haven't found other implementations on github). But the custom implementation HotfixLine is probably not needed anymore. At least the added regression tests will pass with the original IGherkinLine implementation from this repository.

📋 Checklist:

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.

1 participant