-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
ArC - get rid of reflection fallback for private injection points #12597
Comments
/cc @manovotn |
@manovotn @stuartwdouglas @geoand WDYT? |
I would like to see some data on how much it would affect hot reload time, startup time, and how much memory it would save. My gut feeling is that it is not really worth it, but without numbers I am just guessing. |
I am pretty sure we already do this in other places, but having it here would be further reaching so it would be nice to have some figures to compare |
@stuartwdouglas I would expect: hot reload time - slightly increase, startup time - no change, native memory - slightly decrease. But it really depends on the app. And I think it's quite tricky to measure. My original motivation was to get rid of the warnings we log for private injection fields. These warnings are probably too strict anyway because many extensions register dozen of classes for reflection... @geoand Yes, we already remove |
I think this is good idea. Although overall, it wouldn't affect a user that wants to optimize (e.g. such user still shouldn't use private fields in the first place) and at the same time it would allow greenfield projects (or migrating projects) to code whichever way they want without getting warnings and ultimately giving the upper-hand to native apps. So long as we keep the notion of no using private injection fields as means of optimization, I think this is a good step forward. |
I'm wondering if we should just throw an error in this case now, rather than a warning and have a configuration knob to allow it. But maybe I'm a bit too radical :). |
@gsmet There are people who consider private injection points a good practice and they're not going to forgive us ;-). |
I agree that it's too harsh of a measure |
Any updates on this? |
Just to be clear - private field injection works fine even now but a reflection-based fallback is used. |
Since JEP181 it is no longer necessary for compilers to do that. They could use nests instead. And they should, because that is be more efficient, if I understand the matter correctly (which is far from guaranteed to be honest). |
I've added a possible solution to this in #30278 |
After some time spent delving into the depths of private field injection, I came up with a conclusion that the solution proposed here (#12597 (comment)) as well as my proposal in #30278 will both have very limited effect on reducing reflection fallback usage overall. The reason is that we can only perform transformation for actual bean impl classes - meaning a proper class-based bean which has The following scenarios will still require reflection:
Combining any of the above with private IP scenario means we will attempt to perform transformation but will end up registering the class for reflection nonetheless.
EDIT: I have been able to get the related PR to the state where it passes all the tests we are running and have therefore merged it. |
Currently, we have a reflection fallback for private injection points. This is not ideal. In theory, we could get rid of the reflection fallback if we transform the original class and add a package-private synthetic "setter" method that could be used from the bean metadata class.
The downside of this approach is the cost of transformation.
NOTE: This approach is similar to what the compiler does for nested classes that need to access a private member.
The text was updated successfully, but these errors were encountered: