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

Move new {...} outside of inline method in SemiAuto derivation #1785

Merged
merged 2 commits into from
Jul 5, 2023

Conversation

kyri-petrou
Copy link
Collaborator

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 to new { ... } 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 of Auto.derived, whereas any child nodes will be derived using Schema.derived which already uses a non-inlined method to create the Schemas.

Copy link
Owner

@ghostdogpr ghostdogpr left a comment

Choose a reason for hiding this comment

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

Nice!

@ghostdogpr ghostdogpr merged commit 6b44dd7 into series/2.x Jul 5, 2023
10 checks passed
@ghostdogpr ghostdogpr deleted the improve-semiauto-derivation branch July 5, 2023 22:37
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.

None yet

2 participants