-
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
Move reflection and serialization configuration from Feature to json #29886
Move reflection and serialization configuration from Feature to json #29886
Conversation
Thx for sharing 🙏 One small question: How did you fix the issues related to optional services which cause several native tests to fail (kafka and graphql)? Indeed the difference between before and this PR, is the fact that a class was registered only if it could be initialized (indeed calling To workaround the problem, I propose to be able to define conditions essobedo@d7bbed3 WDYT? As you can see, the build is not yet over but all the native tests pass |
I probably didn't. I only tested with a few integration tests, so I probably never crossed these issues.
Hmmm, that's a good point. I guess we should either way remove classes that can't be initialized.
In Quarkus we ask anything reachable to be build-time initialized, so I am not sure that holds in Quarkus.
Nice, I like the addition of the conditions but it also makes me wonder... Don't we know what's reachable and what's not at the deployment phase of Quarkus? Why do we need to offset this to |
It is what I thought at first too, so before adding a class to the generated JSON file, I tried to initialize the class first but in practice it makes even more tests to fail due to a native compilation issue so obviously, there is a difference in terms of available classes between the deployment phase and the native compilation. TBH I did not dig much to understand the difference especially because I believed that it is still interesting to have a way to add a condition on class registration, we then get even more control than before. |
Maybe I missed something so let's try again ccee464 and see the results of the build |
Well, I am curious to see what makes the failing to register classes (e.g. |
OK so it looks like such classes are added using generic getters like in Line 433 in e12ebe1
The class exists in the Quarkus index (i.e. it's reachable), but Quarkus doesn't know it can't be loaded due to missing dependencies, so there indeed doesn't seem to exist a smart way to avoid getting it in the candidates list in the first place. |
Please note that in theory, AFAIU, the class |
It's not clear to me what the best approach would be here. The condition is indeed a generic that can allow us to overcome such issues, but on the other hand Quarkus should avoid registering blindly classes even if they can be build-time initialized as this is adding overhead to the application. I think as far as this PR is concerned I am going to cherry pick your commit with the conditional registration. |
The Native Tests - Messaging1 job fails with |
Yeah we know, it is what I mention in this comment #29886 (comment) |
e12ebe1
to
67a776e
Compare
Here is the kind of error you get if you initialize the class during the build deployment phase https://github.com/essobedo/quarkus/actions/runs/3704534875/jobs/6277704690#step:12:482 |
this.constructors = constructors; | ||
this.weak = weak; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Awesome! Just some cosmetic remarks
core/deployment/src/main/java/io/quarkus/deployment/steps/NativeImageReflectConfigStep.java
Outdated
Show resolved
Hide resolved
...deployment/src/main/java/io/quarkus/deployment/steps/NativeImageSerializationConfigStep.java
Outdated
Show resolved
Hide resolved
...deployment/src/main/java/io/quarkus/deployment/steps/NativeImageSerializationConfigStep.java
Outdated
Show resolved
Hide resolved
67a776e
to
9d76d5c
Compare
This comment has been minimized.
This comment has been minimized.
The build passed so I guess that the PR is ready for review |
...ment/src/main/java/io/quarkus/deployment/builditem/nativeimage/ReflectiveClassBuildItem.java
Show resolved
Hide resolved
...main/java/io/quarkus/deployment/builditem/nativeimage/ReflectiveClassConditionBuildItem.java
Show resolved
Hide resolved
core/deployment/src/main/java/io/quarkus/deployment/steps/ReflectiveHierarchyStep.java
Show resolved
Hide resolved
8fc87f4
to
9a71acf
Compare
As of GraalVM 21.1 finalFieldsWritable is no longer needed when registering fields for reflection.
e02e08d
to
9023ce7
Compare
#30633, taking care of this, is now merged as well. |
This comment has been minimized.
This comment has been minimized.
✔️ The latest workflow run for the pull request has completed successfully. It should be safe to merge provided you have a look at the other checks in the summary. |
This has the following benefits:
Feature
class and figure out what's going onPerformance considerations
In a related zulip chat discussion some concerns about performance where brought up so I am adding some comments on that as well.
This patch should only affect native image generation times (not runtime). This PR only affects how we inform
native-image
about the classes we would like to register for reflection and serialization. With this PR we hand a json file tonative-image
and ask it to parse it and do the necessary registrations for us. Before this PR we were explicitly invoking the GRAAL VM API to do the registrations our selves.According to my measurements the transition from explicitly invoking the API versus passing a json file doesn't have a significant impact on the native image generation times.
Results using the API:
Results using the json file
Relates to #25975
Fixes: #29693
cc @essobedo