-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
ArC: performance optimizations related to client proxy invocations #36626
Conversation
bf0a8cd
to
7e34271
Compare
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just my ordinary nitpicking, nothing unusual.
The 2nd commit I believe we could apply to all normal scopes for which only 1 context is registered. It makes sense to keep ClientProxies.getApplicationScopedDelegate()
separate, because we know that the application context is always active (and so the implementation is more performant); for other contexts, where we either don't know at all or we know that the context may be inactive, the getRequestScopedDelegate()
implementation would be appropriate.
independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/BeanProcessor.java
Outdated
Show resolved
Hide resolved
independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/BeanProcessor.java
Outdated
Show resolved
Hide resolved
...projects/arc/processor/src/main/java/io/quarkus/arc/processor/ContextInstancesGenerator.java
Show resolved
Hide resolved
...ojects/arc/processor/src/main/java/io/quarkus/arc/processor/ComponentsProviderGenerator.java
Outdated
Show resolved
Hide resolved
independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/ArcTestContainer.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to give my feedback mostly over Zulip so just a few bits here.
Overall, I am not a big fan of replacing a nice API such as Map with this generated class, but I understand the motivation and the results seem to support it, so +1.
The 2nd commit I believe we could apply to all normal scopes for which only 1 context is registered. It makes sense to keep ClientProxies.getApplicationScopedDelegate() separate, because we know that the application context is always active (and so the implementation is more performant); for other contexts, where we either don't know at all or we know that the context may be inactive, the getRequestScopedDelegate() implementation would be appropriate.
I also agree with Ladislav in this point - we can apply the same logic to any normal scope and the optimization will be applicable in majority of cases as having multiple scope implementations is rare.
extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/ArcConfig.java
Show resolved
Hide resolved
...dent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/ClientProxyGenerator.java
Outdated
Show resolved
Hide resolved
- introduce the ContextInstances abstraction - if optimization is enabled then generate the ContextInstances implementation for application and request context
7e34271
to
4ef44f9
Compare
- for normal scopes for which a single context is registered - similar to how we optimize the client proxy delegate access for application context
4ef44f9
to
0ac910a
Compare
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/BeanProcessor.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, my only comment is nitpicking :-)
d34495c
to
c5b3fe7
Compare
This comment has been minimized.
This comment has been minimized.
c5b3fe7
to
d6c9f73
Compare
Failing Jobs - Building d6c9f73
Full information is available in the Build summary check run. Failures⚙️ JVM Tests - JDK 21 #- Failing: integration-tests/virtual-threads/mailer-virtual-threads
📦 integration-tests/virtual-threads/mailer-virtual-threads✖
|
The first commit introduces the
ContextInstances
abstraction and generates the implementations for application and request contexts by default. The main goal is to avoidConcurrentHashMap
lookups in the hot path (i.e. for every client proxy invocation).The generated implementation of an application context for config-quickstart looks like:
https://gist.github.com/mkouba/df6526fe8f3c76d4b773b814e1359555
Our benchmarks show that for application context the throughput has increased significantly: I've observed ~ 75% for 1 bean and ~ 25% for 200 beans. The size of the generated class is ~ 3KB for one bean and ~ 200KB for 200 beans. The numbers are lower for request context because in this case the container has to do much more (e.g. check if the context is active). This optimization can be disabled with
quarkus.arc.optimize-contexts=false
.The second commit is similar to how we optimize the client proxy delegate access for the application context. However for the request context, we can only do this optimization if a single request context implementation is registered. I've observed ~ 20% improvement in the RequestScopedProxyInvocationBenchmark.