-
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
Speedup ContextInstances::removeEach if there are null instances #38737
Conversation
ec09241
to
82a333c
Compare
...projects/arc/processor/src/main/java/io/quarkus/arc/processor/ContextInstancesGenerator.java
Outdated
Show resolved
Hide resolved
...projects/arc/processor/src/main/java/io/quarkus/arc/processor/ContextInstancesGenerator.java
Outdated
Show resolved
Hide resolved
82a333c
to
e2c22a3
Compare
e2c22a3
to
2cf5be0
Compare
@mkouba what surprise me (mostly because I'm very ignorant on the topic) is that an empty quarkus application (not even an hello world endpoint) still generate 2
I would like to understand what is deciding how many fields should be created, if possible |
This comment has been minimized.
This comment has been minimized.
2cf5be0
to
2ab88ae
Compare
Each field represents a bean of the given scope. Since your app is empty these beans are provided by the extensions. They are also unremovable; either by definition or marked by an extension. |
Status for workflow
|
@Ladicek @mkouba putting this on draft: this could be a better and more complete fix -> https://github.com/franz1981/quarkus/commits/main_lazy_ctx_instances/ |
This change was due to:
which has a compute as
in short: is the case where there's a generated
ContextInstances
with N > 1 instances fields but just a single one computed (ie not null).Before this PR we are going to perform 3 * N atomic volatile ops (using strong memory barriers), despite just 1 would be necessary.
The 3 atomic ops are:
ie:
null
on the instance field@mkouba @Ladicek
I have no idea which cutoff value make sense here and, as said in the previous comment at
this is another small problem, which could be solved by using
VarHandle::setRelease(..., null)
on the volatile instance field, while holding the lock, but I would raise this in a separate PR.TBH this one is already decent, because it saves the 3 atomic ops to happen in one go; but is assuming that when a value is
null
is a terminal behavior and if a compute happen concurrently,remove
can still observe it as uninitialized.My only concern ATM is that we have (regardless this PR) a lot of "undefined" states in the 2
ContextInstances
impls, which are prone to both optimizations/concurrency misbehaviour, and I would like, in a separate issue, to state which ones are admissible/wrong/rare but still admissible based on how we use things.