-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
Codegen generates inefficient Java code for List
parameters
#282
Comments
Unfortunately, the semantics that we want are that of an immutable list, not merely an unmodifiable list. So if we did not create a new list first, then when creating a As demo:
While what we want:
|
Most of the time, the input parameters are created by the cucumber framework itself. Can't we trust the caller that he will not change the |
I don't think we'd make any changes intentionally. But these messages are shared across threads, if there are mistakes, problems would be incredibly hard to spot and impossible to trace back to their origin. A possible solution would be to use `List.copyOf`` and then use an immutable collection where possible in the caller. But that requires Java 10+. |
Yes, Java 10+ |
Under consideration in cucumber/cucumber-jvm#2962 but no time line attached. Looking at the timeline that JUnit 5 is following, I would expect September 2025. |
👓 What did you see?
For
List
parameters, the codegen generates Java code which looks like this:This means that the
cells
parameters is converted toArrayList
(a modifiable list), then to a non-modifiable list.I think this is done to ensure a proper conversion from
Collection
->ArrayList
->UnmodifiableList
.However, all list arguments are
List
and notCollection
(seejava.rb
). This lead to inefficient code because two list allocations are done, no matter the input list is a modifiable or non-modifiable list.The performance impact has been detected while working on cucumber/gherkin#361, using IntelliJ Profiler (it's hard to see the real impact because there is a lot of generated classes which suffer from this syndrome).
✅ What did you expect to see?
If the
java.java.erb
code generator see aList
, it should generate convert it to a non-modifiable list usingunmodifiableList(List)
without doing anew ArrayList(Collection)
.This will avoid memory allocation and list traversal, so will lead to faster code.
📦 Which tool/library version are you using?
gherkin 31.0.0 (which uses messages-27.2.0)
🔬 How could we reproduce it?
The test-case below shows the issue:
📚 Any additional context?
No response
The text was updated successfully, but these errors were encountered: