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

Any plans to support native-image? #854

Closed
wangliang181230 opened this issue Jan 9, 2023 · 7 comments
Closed

Any plans to support native-image? #854

wangliang181230 opened this issue Jan 9, 2023 · 7 comments

Comments

@wangliang181230
Copy link

wangliang181230 commented Jan 9, 2023

  1. com.github.benmanes.caffeine.cache.NodeFactory.newFactory(Caffeine<K, V> builder, boolean isAsync); uses reflection.
@wangliang181230 wangliang181230 changed the title any plans to support native image Any plans to support native-image? Jan 9, 2023
@ben-manes
Copy link
Owner

That should be compatible, it simply requires including the required classes in the reflection configuration. Graal, Micronaut, Spring seem to support native image with caffeine. When I asked them if we should do anything, I was told that was the framework’s responsibility to maintain. I guess look at what they did as a reference.

@wangliang181230
Copy link
Author

The application of springboot3 provides RuntimeHintsRegistrar to register classes that need reflection.

@wangliang181230
Copy link
Author

class TestRuntimeHints implements RuntimeHintsRegistrar {

    @Override
    public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
        ReflectionHints reflectionHints = hints.reflection();
        reflectionHints.registerType(clazz, INTROSPECT_DECLARED_CONSTRUCTORS, INVOKE_DECLARED_CONSTRUCTORS);
    }

}

@wangliang181230
Copy link
Author

wangliang181230 commented Jan 9, 2023

/META-INF/spring/aot.factories

org.springframework.aot.hint.RuntimeHintsRegistrar= \
xxx.TestClientRuntimeHints

@ben-manes
Copy link
Owner

fyi, you might want to conditionally include the Caffeine classes that are specific to the configuration. We codegen the entry types to minimize memory overhead, which was a good strategy pre-AOT because unloaded classes are free. If instead included in an AOT build then this will add significant bloat (see quarkusio/quarkus#12961).

@wangliang181230
Copy link
Author

wangliang181230 commented Jan 10, 2023

fyi, you might want to conditionally include the Caffeine classes that are specific to the configuration. We codegen the entry types to minimize memory overhead, which was a good strategy pre-AOT because unloaded classes are free. If instead included in an AOT build then this will add significant bloat (see quarkusio/quarkus#12961).

When I register all of the Caffeine classes, the size of the exe file, as well as the memory, has only increased by about 1.5M ~ 2.5M, not 14M.

However, I also think that less registration is better. I will only register the classes used.
Thank you.


my exe files:

图片

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

No branches or pull requests

2 participants