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

[Java] Improve expression creation performance #187

Merged
merged 6 commits into from
Dec 8, 2022

Conversation

jkronegg
Copy link
Contributor

@jkronegg jkronegg commented Dec 5, 2022

πŸ€” What's changed?

Refactored ExpressionFactory to improve expression creation performance by about 50%.

⚑️ What's your motivation?

Fixes #185

🏷️ What kind of change is this?

  • 🏦 Refactoring/debt/DX (improvement to code design, tooling, documentation etc. without changing behaviour)

♻️ Anything particular you want feedback on?

The PR has been asked by mpkorstanje

πŸ“‹ Checklist:

  • I agree to respect and uphold the Cucumber Community Code of Conduct
  • I've changed the behaviour of the code
    • I have added/updated tests to cover my changes.
  • My change requires a change to the documentation.
    • I have updated the documentation accordingly.
  • Users should know about my change
    • I have added an entry to the "Unreleased" section of the CHANGELOG, linking to this pull request.

Improved expression creation performance by about 50%.
Added test case for empty cucumber expression.
Copy link
Contributor

@mpkorstanje mpkorstanje left a comment

Choose a reason for hiding this comment

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

Cheers, this looks good but it is liable to be cleaned up by someone who things this code is very ugly.

Refactored code according to PR comments.
@mpkorstanje mpkorstanje self-assigned this Dec 5, 2022
Copy link
Contributor

@mpkorstanje mpkorstanje 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. I'll try and merge and release this soonish.

@jkronegg jkronegg changed the title Patch 1 Refactored ExpressionFactory to improve expression creation performance Dec 6, 2022
I made a benchmark with JMH which shows that the modified method is about 15% faster (see escapeRegex2 below) :

Benchmark                                  Mode  Cnt       Score       Error  Units
CucumberExpressionBenchmark.escapeRegex0  thrpt   25  726563,091 Β± 15558,020  ops/s
CucumberExpressionBenchmark.escapeRegex1  thrpt   25  782046,026 Β± 10993,804  ops/s
CucumberExpressionBenchmark.escapeRegex2  thrpt   25  833512,235 Β± 25088,968  ops/s

The `CucumberExpression` class looks extensively tested, thus I didn't added more test cases.

Note: for completeness, I tested another variant (escapeRegex1) which replaces the `ESCAPE_PATTERN.matcher(text).replaceAll(String)` with multiple `String.replace(String,String)` : the performance is not that good (only 8% faster than the original method) and code readability/maintenance is bad. But it was interesting to have the numbers to compare...
@aslakhellesoy
Copy link
Contributor

In order to keep the implementations consistent I think it would be a good idea to port this to the other implementations too.

@mpkorstanje mpkorstanje changed the title Refactored ExpressionFactory to improve expression creation performance [Java] Improve expression creation performance Dec 8, 2022
@mpkorstanje
Copy link
Contributor

@aslakhellesoy #190

@jkronegg
Copy link
Contributor Author

jkronegg commented Dec 9, 2022

I added cucumber-expressions 16.1.1 to my Maven dependencies (overrides the version 16.0.0 used in cucumber-core 7.9.0) and the profiler says it's 37% faster. 😁

@fslev
Copy link

fslev commented Dec 11, 2022

Well done. I've ran my suite of ~1000 scenarios in dry-run mode and instead of 37s I've got 13s with the latest release. Almost 300% performance boost.

@mpkorstanje
Copy link
Contributor

@jkronegg now available in Cucumber 7.10. Much appreciated!

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.

Improve Expression creation performance
4 participants