Reduce getter calls during fields mapping #347
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Partially resolves #346
This is proof of concept PR which shows that we can reduce unnecessary getter and setter calls by using variables.
This PR isn't complete and it doesn't handle primitive types. For some reason, I cannot create variables with primitive types and that is why I use primitive type wrappers (i.e.
Long
instead oflong
,Integer
instead ofint
, etc.).Unfortunately, I couldn't correctly resolve problems with objects which has fields with primitive type.
I have included
SingleGetterCallTestCase
test caseshouldMapWithSingleGetterCall
which shows this problem. The PR correctly works with non primitive data types and you can see that the amount of getter calls is generally decreased about 2 times (often 1 call instead of 3 calls, 2-3 calls instead of 5 calls.) It is possible to decrease those calls more (possibly to 1 call) if we add variable values togenerateEqualityTestCode
insideSpecification
but for now I just extended implementation ofgenerateMappingCode
.That said, it is just a proof of concept. I couldn't resolve the issue with primitive data types. If anyone knows what am I doing wrong or how to correctly handle primitive types, I would love to hear that and will try to resolve the issue. As I understand, we should use unwrapped primitive types somewhere and wrapped primitive types somewhere else but I am not sure where exactly.
Also, if you someone wants to finish this optimization, feel free to take this PR and make any changes. I would really love to see this optimization to be implemented.
Stack trace: