Skip to content
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

[GR-62002] [Native Image] System.getProperties evaluates all Lazy expensive values #10630

Open
2 tasks
radcortez opened this issue Feb 5, 2025 · 8 comments
Open
2 tasks

Comments

@radcortez
Copy link

Describe the Issue

In Quarkus, to populate certain pieces of the configuration, we need to look up the available names in multiple sources (System, ENV, etc.).

The only way to retrieve the list of names coming from System properties is by calling System.getProperties(), and then either iterate the keys or call .propertyNames, stringPropertyNames.

Unfortunately, this means that we always have to pay the price of the expensive computation of the lazy values implemented in the substitution here: https://github.com/oracle/graal/blob/master/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/SystemPropertiesSupport.java#L209-L212

We do measure a 5-6 ms startup time in our environments, which we would like to avoid since we don't need the values at all, and just the available names set by System properties. We did workaround the issue by adding a substitution in the entire Properties returned by System, but this is far from ideal: quarkusio/quarkus#45997

I'm happy to work and submit a PR with an agreement on what the solution could be.

Using the latest version of GraalVM can resolve many issues.

GraalVM Version

java 21.0.5 2024-10-15 LTS
Java(TM) SE Runtime Environment Oracle GraalVM 21.0.5+9.1 (build 21.0.5+9-LTS-jvmci-23.1-b48)
Java HotSpot(TM) 64-Bit Server VM Oracle GraalVM 21.0.5+9.1 (build 21.0.5+9-LTS-jvmci-23.1-b48, mixed mode, sharing)

Operating System and Version

Darwin Kernel Version 23.6.0: Mon Jul 29 21:13:00 PDT 2024; root:xnu-10063.141.2~1/RELEASE_X86_64 x86_64

Troubleshooting Confirmation

Run Command

NA

Expected Behavior

Have a way to call System.getProperties and the list of names without incurring the penalty cost of evaluating the lazy values.

Actual Behavior

NA

Steps to Reproduce

NA

Additional Context

No response

Run-Time Log Output and Error Messages

No response

@selhagani
Copy link
Member

Hi radcortez,
Thank you for reaching out to us about this!
Could you please try using the latest available GraalVM version to test this issue? You can find it here: https://github.com/graalvm/graalvm-ce-builds/releases/
Please do let us know if you are still facing this issue even after updating.

@radcortez
Copy link
Author

Yes, it also happens in the latest version. If you notice, the main code is initializing all the System properties:

https://github.com/oracle/graal/blob/master/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/SystemPropertiesSupport.java#L209-L212

This method is used as a Substitution for System.getProperties:
https://github.com/oracle/graal/blob/master/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JavaLangSubstitutions.java#L386-L389

@selhagani selhagani changed the title [Native Image] System.getProperties evaluates all Lazy expensive values [GR-62002] [Native Image] System.getProperties evaluates all Lazy expensive values Feb 6, 2025
@selhagani
Copy link
Member

We will take a closer look into this and I'll make sure to keep you updated. Thank you.

@radcortez
Copy link
Author

Thanks!

@christianhaeubl
Copy link
Member

@radcortez : is the difference still measurable now that #10613 was merged?

@radcortez
Copy link
Author

@christianhaeubl
Copy link
Member

Thanks!

Yes, getting the Properties still forces the initialization. However, for correctness reasons, we had to convert a few of the lazy initializations to eager initializations. So, it is possible that there is no longer a measurable difference.

@radcortez
Copy link
Author

I'll give it a try.

Regardless, shouldn't we have a way to get a list of the property names without incurring the initialization cost?

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants