-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Bad performance during TestStep creation #2666
Comments
Very interesting. I would be happy to accept option 6. That said, I'm going to have to find some broader consensus on the use ChatGTP. It has been known to reproduce it's training data more or less verbatim. |
@mpkorstanje : I'll do a PR with option 6. Regarding ChatGPT, you may be interested by the transcript of option 3 (I finally did not include the last solution proposed by ChatGPT because it was becoming unreadable code) : |
Changed implementation to use variant 6 proposed in cucumber#2666 .
Refactored `TestAbortedExceptions` `Predicate` creation. Performance gain (`Predicate` creation is about 50'000 times faster). Fixes #2666
On my project with ~400 scenarios, the cucumber tests execution duration is on average 20.5 seconds instead of 24.3 seconds (that's a 16% improvement). @fslev : could you please test cucumber |
👓 What did you see?
On my Java project with about 400 Cucumber test scenarios and about 150 step definitions, the IntelliJ flame graph shows that creating the TestStep takes about 10% of the total time (that's about 1 second on my project). Most of the time is consumed in the
TestAbortedExceptions.createIsTestAbortedExceptionPredicate()
method. See theflamegraph.png
file in the annexed ZIP file.✅ What did you expect to see?
I expect the
TestAbortedExceptions.createIsTestAbortedExceptionPredicate()
Predicate<Throwable>
creation to be lightweight, with no noticeable impact on the overall execution time.I implemented some variants and did some benchmarking to determine what is the best alternative.
Note: some optimisations have been produced using ChatGPT (on 19.12.2022). I could have written the code by myself but wanted to compare what an IA could produce. The produced code is impressive and could have been produced by human developers. But as human developers, ChatGPT makes mistakes (e.g. the first produced code was not able to identify subclasses), so it needs some code review and test harness.
All variants have been tested using the following JUnit5 test (contains a two positive and one negative example):
Even if the implemented variants pass this tests, there are slight differences with the classloading behavior:
As these use-cases are very rare, we could agree on changing the original behavior if the performance improvement is significative (to be decided by Cucumber core team).
The table below summarizes the different variants:
Based on the results above, my recommendation would be to use
createIsTestAbortedExceptionPredicate6
which keeps the same classloader behavior ("by thread"), without cached classes. This way, the original behavior is conserved, the code readability is improved and the performance is improved (about 48'000 times faster). We could have even better performance, but this would require to change the original behavior (e.g.createIsTestAbortedExceptionPredicate5
orcreateIsTestAbortedExceptionPredicate3
), which may cause side effects on Cucumber users.Below is the proposed method:
I can do a PR with the solution preferred by the Cucumber core team.
📦 Which tool/library version are you using?
Cucumber 7.10.0
🔬 How could we reproduce it?
The ZIP file in annex contains the JMH benchmark and the implemented variants.
runner.zip
These files can be copied in a minimal Maven project with the following dependencies:
The text was updated successfully, but these errors were encountered: