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

Lazily perform reflection when Instance<> is used #45276

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

geoand
Copy link
Contributor

@geoand geoand commented Dec 24, 2024

The idea here is to save a few reflection calls
that might never end up being used (this is the
case with some Quarkus REST providers)

For example io.quarkus.resteasy.reactive.jackson.runtime.serialisers.FullyFeaturedServerJacksonMessageBodyReader
has the following constructor:

    public FullyFeaturedServerJacksonMessageBodyReader(Instance<ObjectMapper> mapper, Providers providers) {
        super(mapper);
        this.originalMapper = mapper;
        this.providers = providers;
    }

With the existing version of the code the generated FullyFeaturedServerJacksonMessageBodyReader_Bean looks (partly) like this:

      Constructor var12 = Reflections.findConstructor(FullyFeaturedServerJacksonMessageBodyReader.class, var8);
      InstanceProvider var13 = new InstanceProvider((Type)var9, var10, this, var11, var12, 0, false);
      FixedValueSupplier var14 = new FixedValueSupplier(var13);

With this change it becomes:

      Supplier var12 = Reflections.findConstructorLazily(FullyFeaturedServerJacksonMessageBodyReader.class, var8);
      InstanceProvider var13 = new InstanceProvider((Type)var9, var10, this, var11, var12, 0, false);
      FixedValueSupplier var14 = new FixedValueSupplier(var13);

This means that if FullyFeaturedServerJacksonMessageBodyReader is never used (which is most of the time), no reflective call will be made to look up its constructor

P.S. The change does the minimum possible to achieve what I had in mind,
it definitely is not polished in any way.

The idea here is to save a few reflection calls
that might never end up being used (this is the
case with some Quarkus REST providers)
@quarkus-bot quarkus-bot bot added the area/arc Issue related to ARC (dependency injection) label Dec 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/arc Issue related to ARC (dependency injection)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant