-
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
Zero-Garbage ContextInstances::forEach #37529
Conversation
4b60011
to
c206da7
Compare
@mkouba wdyt? suggestions on how to make it right? |
I like it! I don't think that we need a default implementation though.
I think that we need it for some use case with context propagation but it shouldn't be used in a hot path.
+1 |
c206da7
to
4e85930
Compare
4e85930
to
098d895
Compare
independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/AbstractSharedContext.java
Show resolved
Hide resolved
🎊 PR Preview b7887aa has been successfully built and deployed to https://quarkus-pr-main-37529-preview.surge.sh/version/main/guides/ |
@mkouba @geoand verified via running Techempower plaintext that we've moved from 3.6 M req/sec to 4 M req/sec |
Great!!! |
This comment has been minimized.
This comment has been minimized.
098d895
to
3ad2ee4
Compare
Just out of curiosity - what caused these failures? |
@mkouba |
3ad2ee4
to
eb8c8a7
Compare
✔️ 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. |
This improvement is necessary due to #36626, which has introduced a very good thing ie bytecode-generated context containers, but it's causing an
Set
allocation in the hot-path, which eventually lead to callingSystem::identityHashCode
as well (which is not known to be super efficient nor fast).The cost of
Arc
in plaintext Techempower fororg/jboss/resteasy/reactive/server/core/ResteasyReactiveRequestContext.close
was at ~2.87% and has become 6.7%, which is ~ twice as costy as it was before the mentioned pr.The flamegraphs shows clearly the problem, before:
The problem was that, with a single ctx instance, the default capacity of
ConcurrentHashMap
was an overkill (16), andforEach
andclear
were forcing to iterate among all map's slots, includingnull
-ones, twice.#36626 has introduced a big improvement on it, but:
Shows that:
HashSet
's are backed by a map using the values as keys, this force the ctx instances to have their own equals/hashCode implementations ore they would rely onSystem::identityHashCode
which is not greatThis pr is "fixing" the "symptom" by providing an optimized
forEach
method given thatContextInstances
is a container itself and I see no harm in this, but still:getAllPresent
method? If is used elsewhere in the hotpath, is probably a good idea to fix there them as well IMO...ApplicationContextInstancesTest
: I still need to write a new test for this additional API method, which use a ctx instances with more than 1 instance inlock/unlock
to happen while reading the instances, which "could" still be an hot-path: I'm not fixing problems which I cannot observe, but calling volatile stores (twice, to enter/exit) in the hot path have some non-negligible performance impact, which could be improved as well. I don't plan to send the fix for it in this PR.