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

Slightly optimize ObjectMapper producer #45445

Merged
merged 2 commits into from
Jan 9, 2025

Conversation

geoand
Copy link
Contributor

@geoand geoand commented Jan 8, 2025

Before this PR, the constructor of the generated _Bean class was:

{
      ClassLoader var20 = Thread.currentThread().getContextClassLoader();
      this.declaringProviderSupplier = var1;
      Type[] var5 = new Type[1];
      ClassLoader var4 = Thread.currentThread().getContextClassLoader();
      Class var6 = Class.forName("io.quarkus.jackson.ObjectMapperCustomizer", false, var4);
      var5[0] = var6;
      Object var7 = null;
      ParameterizedTypeImpl var15 = new ParameterizedTypeImpl(List.class, var5, (Type)var7);
      ClassLoader var8 = Thread.currentThread().getContextClassLoader();
      Class var14 = Class.forName("io.quarkus.jackson.ObjectMapperCustomizer", false, var8);
      HashSet var9 = new HashSet();
      All_ArcAnnotationLiteral var10 = All_ArcAnnotationLiteral.INSTANCE;
      var9.add(var10);
      HashSet var11 = new HashSet();
      All_ArcAnnotationLiteral var12 = All_ArcAnnotationLiteral.INSTANCE;
      var11.add(var12);
      Class[] var13 = new Class[]{List.class, JacksonBuildTimeConfig.class, JacksonSupport.class};
      Method var16 = Reflections.findMethod(ObjectMapperProducer.class, "objectMapper", var13);
      ListProvider var17 = new ListProvider(var14, (Type)var15, var9, this, var11, var16, 0, false, false);
      FixedValueSupplier var18 = new FixedValueSupplier(var17);
      this.injectProviderSupplier1 = (Supplier)var18;
      Set var22 = Qualifiers.IP_DEFAULT_QUALIFIERS;
      Set var23 = Collections.emptySet();
      Class[] var19 = new Class[]{List.class, JacksonBuildTimeConfig.class, JacksonSupport.class};
      Method var24 = Reflections.findMethod(ObjectMapperProducer.class, "objectMapper", var19);
      Class var21 = Class.forName("io.quarkus.jackson.runtime.JacksonBuildTimeConfig", false, var20);
      CurrentInjectionPointProvider var25 = new CurrentInjectionPointProvider(this, var2, var21, var22, var23, var24, 1, false);
      FixedValueSupplier var26 = new FixedValueSupplier(var25);
      this.injectProviderSupplier2 = (Supplier)var26;
      this.injectProviderSupplier3 = var3;
      Object[] var27 = new Object[6];
      Class<Serializable> var28 = Serializable.class;
      var27[0] = var28;
      Class var29 = Class.forName("com.fasterxml.jackson.core.ObjectCodec", false, var20);
      var27[1] = var29;
      Class<Object> var30 = Object.class;
      var27[2] = var30;
      Class var31 = Class.forName("com.fasterxml.jackson.databind.ObjectMapper", false, var20);
      var27[3] = var31;
      Class var32 = Class.forName("com.fasterxml.jackson.core.Versioned", false, var20);
      var27[4] = var32;
      Class var33 = Class.forName("com.fasterxml.jackson.core.TreeCodec", false, var20);
      var27[5] = var33;
      Set var34 = Sets.of(var27);
      this.types = var34;
   }

and now it is:

{
      ClassLoader var15 = Thread.currentThread().getContextClassLoader();
      this.declaringProviderSupplier = var1;
      Set var9 = Qualifiers.IP_DEFAULT_QUALIFIERS;
      Type[] var3 = new Type[1];
      ClassLoader var2 = Thread.currentThread().getContextClassLoader();
      Class var4 = Class.forName("io.quarkus.jackson.ObjectMapperCustomizer", false, var2);
      var3[0] = var4;
      ClassLoader var5 = Thread.currentThread().getContextClassLoader();
      Class var6 = Class.forName("jakarta.enterprise.inject.Instance", false, var5);
      Object var7 = null;
      ParameterizedTypeImpl var8 = new ParameterizedTypeImpl(var6, var3, (Type)var7);
      Set var10 = Set.of();
      InstanceProvider var11 = new InstanceProvider((Type)var8, var9, null, var10, null, 0, false);
      FixedValueSupplier var12 = new FixedValueSupplier(var11);
      this.injectProviderSupplier1 = (Supplier)var12;
      Object[] var13 = new Object[6];
      Class<Serializable> var14 = Serializable.class;
      var13[0] = var14;
      Class var16 = Class.forName("com.fasterxml.jackson.core.ObjectCodec", false, var15);
      var13[1] = var16;
      Class<Object> var17 = Object.class;
      var13[2] = var17;
      Class var18 = Class.forName("com.fasterxml.jackson.databind.ObjectMapper", false, var15);
      var13[3] = var18;
      Class var19 = Class.forName("com.fasterxml.jackson.core.Versioned", false, var15);
      var13[4] = var19;
      Class var20 = Class.forName("com.fasterxml.jackson.core.TreeCodec", false, var15);
      var13[5] = var20;
      Set var21 = Sets.of(var13);
      this.types = var21;
   }

geoand added 2 commits January 8, 2025 16:18
This leads to slightly better generated code
(as the generated _Bean does not need to do
reflection on the java member)
@quarkus-bot quarkus-bot bot added the area/jackson Issues related to Jackson (JSON library) label Jan 8, 2025
@geoand geoand requested a review from gsmet January 8, 2025 14:36
@geoand geoand added the triage/waiting-for-ci Ready to merge when CI successfully finishes label Jan 8, 2025
@gsmet
Copy link
Member

gsmet commented Jan 8, 2025

@mkouba is it expected Instance is better than @All List? Should we look for usage of @All List in our code base? I don't think it's a problem for our users but on our side, we could maybe be more careful if it has value?

@mkouba
Copy link
Contributor

mkouba commented Jan 8, 2025

I'm not a fan of this kind of optimizations. It brings very little value and may cease to apply very quickly. For example, I've mentioned in https://quarkusio.zulipchat.com/#narrow/channel/187038-dev/topic/arc.20startup.20reflection that @All List<> could be optimized so that it does not need to store the current InjectionPoint unless needed.

Also it's not possible to say if Instance is "better" than @All List. It depends on how it's used. But in general it should be comparabale in terms of runtime performance.

CC @manovotn @Ladicek

@geoand
Copy link
Contributor Author

geoand commented Jan 8, 2025

For example, I've mentioned in https://quarkusio.zulipchat.com/#narrow/channel/187038-dev/topic/arc.20startup.20reflection that @ALL List<> could be optimized so that it does not need to store the current InjectionPoint unless needed.

And I can switch back when that lands :)

Copy link

quarkus-bot bot commented Jan 8, 2025

Status for workflow Quarkus CI

This is the status report for running Quarkus CI on commit 74a760a.

✅ The latest workflow run for the pull request has completed successfully.

It should be safe to merge provided you have a look at the other checks in the summary.

You can consult the Develocity build scans.


Flaky tests - Develocity

⚙️ JVM Tests - JDK 21

📦 extensions/smallrye-reactive-messaging-kafka/deployment

io.quarkus.smallrye.reactivemessaging.kafka.deployment.testing.KafkaDevServicesContinuousTestingTestCase.testContinuousTestingScenario2 - History

  • io.quarkus.builder.BuildException: Build failure: Build failed due to errors [error]: Build step io.quarkus.redis.deployment.client.DevServicesRedisProcessor\#startRedisContainers threw an exception: java.lang.RuntimeException: org.testcontainers.containers.ContainerLaunchException: Container startup failed for image docker.io/redis:7 at io.quarkus.redis.deployment.client.DevServicesRedisProcessor.startRedisContainers(DevServicesRedisProcessor.java:124) at java.base/java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:733) at io.quarkus.deployment.ExtensionLoader$3.execute(ExtensionLoader.java:856) - java.lang.RuntimeException
java.lang.RuntimeException: 
io.quarkus.builder.BuildException: Build failure: Build failed due to errors
	[error]: Build step io.quarkus.redis.deployment.client.DevServicesRedisProcessor#startRedisContainers threw an exception: java.lang.RuntimeException: org.testcontainers.containers.ContainerLaunchException: Container startup failed for image docker.io/redis:7
	at io.quarkus.redis.deployment.client.DevServicesRedisProcessor.startRedisContainers(DevServicesRedisProcessor.java:124)
	at java.base/java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:733)
	at io.quarkus.deployment.ExtensionLoader$3.execute(ExtensionLoader.java:856)
	at io.quarkus.builder.BuildContext.run(BuildContext.java:256)
	at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)

@geoand geoand merged commit a7e9da2 into quarkusio:main Jan 9, 2025
52 checks passed
@quarkus-bot quarkus-bot bot added this to the 3.18 - main milestone Jan 9, 2025
@geoand geoand deleted the objectmapper-producer branch January 9, 2025 04:48
@quarkus-bot quarkus-bot bot removed the triage/waiting-for-ci Ready to merge when CI successfully finishes label Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/jackson Issues related to Jackson (JSON library) triage/flaky-test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants