Putting the native GraalVM configs in the main jar? #1930
-
|
Hi @ben-manes, I was looking into an issue raised against my library (Yauaa which uses caffeine) about using it in a GraalVM native application. Some of the comments mentioned that they have to do specific things also for Caffeine to get it running. I'm wondering on how I should handle this in my library. I was thinking about simply including all the configs needed to make this possible in the main jar file, but that requires me to also include these configs for your library, which to me is a bit strange. Now I did notice that you have a clear example on how to use caffeine in a graalvm native application Why did you choose to keep this a separate example and not simply include these configs in the main jar distribution? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 9 replies
-
|
I asked that question to Quarkus when they temporarily wanted me to include reachability metadata. That was before there was a standard format and they used jandex for the manifest. Afterwards they decided against it because it led to larger binaries since it no longer prunes to just what the application uses. For anything configuration-driven the AOT processor cannot know what path to take, causing it to include the universe of classes instead of the relevant subset. Caffeine uses code generation to optimize the memory usage to only the fields in use (e.g. expiration, weak keys). This is ideal on the JVM since there is no cost for unloaded classes and a slightly larger jar file is preferable to wasted memory usage. If AOT is precompiling all variants then it does increase the binary size unnecessarily. I think that is why the JDK team didn't adopt Graal AOT as is and are working on in language pre-computations, precompiled code caches, etc. Currently AOT is more of an expert mode option with common reachability metadata provided by the frameworks (Quarkus', Oracle's graalvm-reachability-metadata and manual fine tuning. AOT explicitly breaks encapsulation, requires expert level tradeoff decisions, and is non-standard Java. Therefore, I don't think its appropriate for users to expect libraries to provide direct support. Taking their needs into consideration and integration testing is already above average. If they are experts then they'll want to tune the reachability metadata anyway, and if they are not then they shouldn't be using AOT. I think in both of our projects having integration testing to ensure it works is good enough and then we can direct those users back to their community for support. So for your next steps, maybe add an example to squash question, serve as an integration test, and redirect users to the |
Beta Was this translation helpful? Give feedback.
-
|
FYI: This is the config I used for my project: https://github.com/nielsbasjes/yauaa/blob/main/analyzer/src/main/resources/META-INF/native-image/nl.basjes.parse.useragent/yauaa/reachability-metadata.json |
Beta Was this translation helpful? Give feedback.
I asked that question to Quarkus when they temporarily wanted me to include reachability metadata. That was before there was a standard format and they used jandex for the manifest. Afterwards they decided against it because it led to larger binaries since it no longer prunes to just what the application uses. For anything configuration-driven the AOT processor cannot know what path to take, causing it to include the universe of classes instead of the relevant subset.
Caffeine uses code generation to optimize the memory usage to only the fields in use (e.g. expiration, weak keys). This is ideal on the JVM since there is no cost for unloaded classes and a slightly larger jar file is prefer…