-1

I'm working on a project that uses gRPC and I want to compile it with GraalVM's native-image for better performance and smaller memory footprint.

I have tried to use native-image directly, but there are a lot of problems with class initialisation. I understand that there might be some specific configurations or steps that I need to take before I can successfully compile my gRPC code with native-image.

Here are some specific areas where I'm looking for guidance:

  1. Are there any specific gRPC features or APIs that are not compatible with native-image?
  2. Do I need to provide any additional configuration files (like reflection configuration) for native-image (Also, I used the shaded plugin to change the location of the grpc package. Might this have an effect on the configuration?)
  3. Are there any known issues or limitations that I should be aware of when using gRPC with native-image?
  4. Are there any best practices or tips?

What are the relevant resources?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
yswdqz
  • 1
  • That is way too many questions. – Peter Mortensen Jun 29 '23 at 18:24
  • Possibly related: *[What is a shaded JAR file? And what is the difference/similarities between an uber JAR and shaded JAR?](https://stackoverflow.com/questions/49810578/what-is-a-shaded-jar-and-what-is-the-difference-similarities-between-uber-jar-a)* – Peter Mortensen Jun 29 '23 at 18:30
  • What is *"the shaded plugin"*? The [Apache Maven Shade Plugin](https://maven.apache.org/plugins/maven-shade-plugin/)? Or something else? – Peter Mortensen Jun 29 '23 at 18:38
  • Apologies for my lack of clarity, I was indeed referring to the Apache Maven Shade Plugin. – yswdqz Jun 30 '23 at 02:35

1 Answers1

0

Yes, shading can cause a lot of breakages for native-image.

native-image is not something that gRPC regularly tests. But it "has worked for someone before." I could believe there is a regression occasionally, but I wouldn't expect there to be lots of issues.

gRPC and some of its dependencies include native-image configuration in the JARs. That information is broken if you relocate the class files without rewriting the configuration. grpc-netty-shaded shades Netty, so gRPC has custom code to rewrite native-image configuration. Thus, if you are shading, I'd expect that to cause problems.

Eric Anderson
  • 24,057
  • 5
  • 55
  • 76