-
Notifications
You must be signed in to change notification settings - Fork 1.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
Code removal regression #2327
Comments
@arodionov do you think this is related to your recent commit on xml packages? |
Yes, this regression is related with the following Feature that enables XML support https://github.com/oracle/graal/blob/master/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/config/JavaxXmlClassAndResourcesLoaderFeature.java |
The XML-parsers support has been added in GraalVM 20.0.0. As a result, if the code that loads parser via reflection is reachable, the specified parser and all related classes will be loaded too. In Java 11 there is another implementation of the java.util.Properties.loadFromXML, with direct SAXParser call (without reflection usage). So, for Java 11 images size shouldn't change between GraalVM versions. |
Thanks for the detailed analysis, @arodionov. For this particular use case (looking up the Though, Spring is always going to use |
Yes, it could be a solution. For Java 11 |
I have been able to restore previous size and memory consumption for our The @arodionov Could you explain how you proceed to diagnose what triggers XML parser usage? I have been myself using |
@sdeleuze There are 8 classes instantiated via reflection, so we create handlers for the following methods where those classes instantiated.
Working on this, to make reachability handlers more precise and include only a limited set of XML-classes. |
@sdeleuze For
|
@arodionov Thanks I am working on fixing those on Spring side. @fhanik Could you have a look to the Tomcat ones? |
Ok so using this branch with various optimizations to remove XML classes using @arodionov guidance and unused converters, I have these figures. Before: After: So we are back at the level of previous figures. Beware that for now I just remove It seems also that a lot of crypto classes are now included, I am wondering if HTTPS support is now detected automatically via the code rather than enabled via a command line parameter, bu that's probably out of the scope of that issue. |
After a second look, XML classes are still included, the great figures I got seems to come for the sum other the various optimizations I did. I have not found yet what triggers their inclusion. If you want to reproduce:
These XML classes are included despite having removed the 4 branches previously mentioned that were triggering XML parsers:
I guess I missed other branches but I have not found yet where they are. I am reporting that to double check there is not an underlying bug or unexpected behavior. |
@sdeleuze Will look again what triggers the XML inclusion. |
Oh I think I found, it could be
|
Ok I managed to remove those one as well by enabling static initialization at build time for those Tomcat classes (security manager is still disabled by default): Build memory: 4.58GB I will let you close this issue when you have finished your optimizations, on my side it is ok. |
This commit introduces various optimizations that allow to significantly reduce Spring Boot applications footprint when compiled as native images. The first one is the capability to remove XML parsers (see related oracle/graal#2327 GraalVM issue) including those configured habitually by Spring. XML Parsers from Logback, Tomcat, Spring Boot, Spring Framework Core/WebMvc/WebFlux can be disabled via -Dspring.graal.remove-xml-support=true and is implemented via various substitutions. Notice for now FormHttpMessageConverter is used instead of AllEncompassingFormHttpMessageConverter due to oracle/graal#2458. It is now also possible to remove SpEL via -Dspring.graal.remove-spel-support=true and JMX via -Dspring.graal.remove-jmx-support=true. BackgroundPreinitializer are now disabled since they do not make sense with GraalVM native. spring-graal-feature is now added as a regular Maven dependency in order to make the new org.springframework.boot.NativePropertiesListener taken in account when the agent is used. Key samples and petclinic ones have been updated to take advantage of those optimizations. Spring Fu samples now also takes advantages of spring-projects-experimental/spring-fu#269 and those capabilities. In the long run, these "not so easy to maintain substitutions" could maybe be replaced by a new GraalVM capability that would monitor used classes by the JVM via an agent and pass this list to native-image compiler to remove those unused classes from the native image in order to load classes lazily like the JVM does. It would also have the advantage to not require an explicit option to enable those optimizations. Closes spring-atticgh-109
This commit introduces various optimizations that allow to significantly reduce Spring Boot applications footprint when compiled as native images. The first one is the capability to remove XML parsers (see related oracle/graal#2327 GraalVM issue) including those configured habitually by Spring. XML Parsers from Logback, Tomcat, Spring Boot, Spring Framework Core/WebMvc/WebFlux can be disabled via -Dspring.graal.remove-xml-support=true and is implemented via various substitutions. Notice for now FormHttpMessageConverter is used instead of AllEncompassingFormHttpMessageConverter due to oracle/graal#2458. It is now also possible to remove SpEL via -Dspring.graal.remove-spel-support=true and JMX via -Dspring.graal.remove-jmx-support=true. BackgroundPreinitializer are now disabled since they do not make sense with GraalVM native. spring-graal-feature is now added as a regular Maven dependency in order to make the new org.springframework.boot.NativePropertiesListener taken in account when the agent is used. Key samples and petclinic ones have been updated to take advantage of those optimizations. Spring Fu samples now also takes advantages of spring-projects-experimental/spring-fu#269 and those capabilities. In the long run, these "not so easy to maintain substitutions" could maybe be replaced by a new GraalVM capability that would monitor used classes by the JVM via an agent and pass this list to native-image compiler to remove those unused classes from the native image in order to load classes lazily like the JVM does. It would also have the advantage to not require an explicit option to enable those optimizations. Closes spring-atticgh-109
This commit introduces various optimizations that allow to significantly reduce Spring Boot applications footprint when compiled as native images. The first one is the capability to remove XML parsers (see related oracle/graal#2327 GraalVM issue) including those configured habitually by Spring. XML Parsers from Logback, Tomcat, Spring Boot, Spring Framework Core/WebMvc/WebFlux can be disabled via -Dspring.graal.remove-xml-support=true and is implemented via various substitutions. Notice for now FormHttpMessageConverter is used instead of AllEncompassingFormHttpMessageConverter due to oracle/graal#2458. It is now also possible to remove SpEL via -Dspring.graal.remove-spel-support=true and JMX via -Dspring.graal.remove-jmx-support=true. BackgroundPreinitializer are now disabled since they do not make sense with GraalVM native. spring-graal-feature is now added as a regular Maven dependency in order to make the new org.springframework.boot.NativePropertiesListener taken in account when the agent is used. Key samples and petclinic ones have been updated to take advantage of those optimizations. Spring Fu samples now also takes advantages of spring-projects-experimental/spring-fu#269 and those capabilities. In the long run, these "not so easy to maintain substitutions" could maybe be replaced by a new GraalVM capability that would monitor used classes by the JVM via an agent and pass this list to native-image compiler to remove those unused classes from the native image in order to load classes lazily like the JVM does. It would also have the advantage to not require an explicit option to enable those optimizations. Closes spring-atticgh-109
It seems there is a big regression at code removal level between 19.3.1 and 20.0.0. The reports mentioned are available in https://github.com/sdeleuze/graal-issues/tree/master/code-removal-regression.
The very same jafu example:
With GraalVM 19.3.1:
With GraalVM 20.0.0:
A diff between packages reports available in the
jafu-sample-19.3.1-reports
andjafu-sample-20.0.0-reports
shows that GraaVM 20.0.0 is unable to detect that following packages and related classes are not used:com.sun.org.apache.xalan
com.sun.org.apache.xerces
com.sun.xml.internal.stream
javax.xml.datatype
javax.xml.namespace
javax.xml.stream
javax.xml.transform
jdk.xml.internal
org.w3c.dom
org.xml.sax.helpers
Same problem with the jafu-webmvc one:
With GraalVM 19.3.1:
With GraalVM 20.0.0:
Similar diff with a lot of XML related classed can be observed between packages reports available in the
jafu-webmvc-sample-19.3.1-reports
andjafu-webmvc-sample-20.0.0-reports
.The text was updated successfully, but these errors were encountered: