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 RequestContext - get rid of LazyValue for container lifecycle events #28330
ArC RequestContext - get rid of LazyValue for container lifecycle events #28330
Conversation
mkouba
commented
Sep 30, 2022
- to speed up the request context activation/deactivation in majority of cases
This comment has been minimized.
This comment has been minimized.
36739bd
to
5c1bef0
Compare
I've also added the RequestContextActivationBenchmark but the results are a bit surprising. I can see a small perf drop in the 2.12 branch, which is expected - we added some trace logging in the UPDATE: I did replace the In any case, I think that these changes make the code more readable. So I'd like to merge this anyway. |
independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/RequestContext.java
Outdated
Show resolved
Hide resolved
5c1bef0
to
6e78bda
Compare
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, I'd just call it IS_VALID
instead of VALUE
, but that's nitpicking.
@franz1981 yet another piece of the performance puzzle :-) |
Just a thing
Did you tried with an
|
I did notice that
Why is that? |
Because there are no atomic ops in any instruction sets involving such tiny types in any CPU archs- meaning that something is happening to make it happen... |
FTR, my OpenJDK 11 includes atomic ops for booleans (as conversions to/from bytes, see |
not saying it isn't work, but I don't know what it does under the hood :) |
The field doesn't become an int, but the CAS operation is implemented as if there was an int (with bit masking to avoid changing the nearby memory). I guess it would be fine to make the field |
The field must be aligned as int to make it work, while in the field declaration (maybe) here is boolean (and JOL can show how is packed in the class layout), unless is declared In C++ sadly makes the ops on types that doesn't support the right "grain" to become a locked one (for real), that's why I'm asking I don't know how RequestContextState's isValid is declared here |
Ok, I can't say I completely understand all the comments above but let's use |
My understanding has been that |
I've verified that the ASM produced for And "mystery" solved too:
Their perf is exactly the same, because moving byte/int register(s) to memory won't make much difference (cache invalidation is still with much higher granularity anyway and hw barriers are way more costy) hence
the CAS is implemented as native byte (I was wrong, x86 cannot do it with bit-level granularity, my faulty memory, sorry) and no masking is happening if not the one implemented on ASM level eg lock cmpxchg %r8b,0xc(%r12,%r10,8) vs lock cmpxchg %r8d,0xc(%r12,%r10,8) the |
This comment has been minimized.
This comment has been minimized.
- get rid of LazyValue for container lifecycle events - get rid of the synchronized block in the destroy() method - this should speed up the request context a little bit in majority of cases
6e78bda
to
88e9c41
Compare
This comment has been minimized.
This comment has been minimized.
Ah my bad, I only looked at the Java code, and there's apparently an intrinsic for the |
Nice! |