-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Save setting the same state in the Vertx local data duplicated context #34132
Conversation
b5cea49
to
a161407
Compare
independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/RequestContext.java
Show resolved
Hide resolved
independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/RequestContext.java
Outdated
Show resolved
Hide resolved
independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/RequestContext.java
Outdated
Show resolved
Hide resolved
extensions/vertx/runtime/src/main/java/io/quarkus/vertx/runtime/VertxCurrentContextFactory.java
Show resolved
Hide resolved
And now that's the last thing I would like to understand
@mkouba ? |
Just noticed a thing @Override
public void activate(ContextState initialState) {
if (LOG.isTraceEnabled()) {
traceActivate(initialState);
}
if (initialState == null) {
currentContext.set(new RequestContextState(new ConcurrentHashMap<>()));
// Fire an event with qualifier @Initialized(RequestScoped.class) if there are any observers for it
fireIfNotEmpty(initializedNotifier);
} else {
if (initialState instanceof RequestContextState) {
currentContext.set((RequestContextState) initialState);
} else {
throw new IllegalArgumentException("Invalid initial state: " + initialState.getClass().getName());
}
}
}
on |
I think that it's fine in general. Note that the work performed by In most applications the quarkus.arc.context-propagation.enabled=false should be a safe performance boost (unless the SmallRye Context Propagation API is used explicitly). |
That's awesome, do we have any docs on this for our users to explain it? Is it worthy? |
Probably best to squash the commits |
65e4799
to
09e16be
Compare
It's not documented AFAIK. The problem is that there isn't agreement on how and when to use it 🤷. BTW there's #34123. |
Performance difference is pretty relevant I see; and I've removed smallrye decoration as well; getting another (small) performance boost. |
extensions/vertx/runtime/src/main/java/io/quarkus/vertx/runtime/VertxCurrentContextFactory.java
Show resolved
Hide resolved
Where are we with this one? Is it ready to be merged? IIUC, we decided to not drop the ConcurrentHashMap because it could lead to subtle issues and we are not yet in a state where we can say that we explicitly don't support the cases that would break. Is that accurate? |
I need to rebase it and yep, we are ready to go!
Yep, we can talk about the future of such in a separate call, but in the current state avoiding wasteful CHM::put seems the easier thing to do ATM |
👌 |
09e16be
to
61bd514
Compare
So unless there are any objections, let's merge this when CI goes green |
extensions/vertx/runtime/src/main/java/io/quarkus/vertx/runtime/VertxCurrentContextFactory.java
Show resolved
Hide resolved
+1 for merging |
This is part of a bigger problem shown by some benchmarks ie https://github.com/franz1981/quarkus-reactive-beer
Feel free to try it at home, it should be able to collect flamegraphs as well and is not I/O bound nor using a database (that means, how much is relevant what I've found, that's a fair and separate question)
Some evidence that is a worthy change:
In violet you can see the
VertxCurrentContext.set
calls, which set the sameio.quarkus.arc.impl.RequestContext$RequestContextState
over and over in the same context.In my case, it happens a lot more often because it is filtering the elements (12) twice (I have observed ~50 identical
VertxCurrentContext.set
), while with a simpler one (which mimic what hibernate reactive would do while performing a query), just ~4.In both cases, avoiding performing
CHM::put
seems a great idea, given that would benefit card marking as mentioned already at #30024My concern now is that is now biased to make it pay more when such replacement happen instead, how much is it common? @mkouba ?
FYI the othe remaning low hanging fruit cost of context propagation is smallrye/smallrye-context-propagation#424
NOTE
this PR include some code refactoring in the caller class (performing activation) to remove from the methods the "slow paths" and makes smaller (in term of bytecode) each of the refactored methods: this would increase the chance to get inlined according to the OpenJDK inlining mechanism. It would be a great practice to always do like that, if won't harm the eyes of the readers (it shouldn't but is personal!).