Move new {...}
outside of inline method in SemiAuto
derivation
#1785
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.
I've been playing abit with code derivation lately, and it seems that having
new Foo{ ... }
used in inline methods can be fairly bad especially when used alongside derivation. What happens is that the call tonew { ... }
is inlined at every callsite, which causes a new anonymous class to be created, which can lead to a big increase in the number of generated classes, potentially killing the JIT code cache (see somewhat related issue).In the case here, since we're only exporting 2 methods it's not particularly bad. However, I tested these changes in a medium/small-sized application and the number of classes in the final JAR was reduced from 800 to 700, and the size was reduced from 2.2MB down to 1.9MB.
Unfortunately, we can't do the same with
Auto
as I can't figure out a way to get the auto-derivation to work. However that's not as big of an issue since only the top-level derivation will use the implementation ofAuto.derived
, whereas any child nodes will be derived usingSchema.derived
which already uses a non-inlined method to create theSchema
s.