-
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
Avoid loading the list of ArC removed beans into the heap #18345
Comments
P.S. we need to think how this impacts native-image: serialization might be an issue, but also I wouldn't want the classes which represent the "removed types" to still be part of the code which can not be DCE'd because of Serialization needing to being able to load it. |
For the sake of completeness, it is possible to remove this information via
Hm, this might be tough although not impossible. Take for example the parameterized types and the complexity of CDI type-safe resolution rules... |
FTR after we merged the micro optimizations from the #18567 the resulting set of removed beans will usually take a few tens of kilobytes of heap (8 KB for the hibernate-orm-quickstart) which is probably acceptable in most cases. For others, |
Should we close this given ^ ? |
Well, we can still do better and save few tens of kilobytes of heap ;-). I'd like to keep this issue open but the priority is very low. |
So I managed to load the removed beans lazily but then realized that many extensions unfortunately use the "try-to-get a bean instance programmatically" pattern during initialization (and handling the potential We would have to add something like |
As far as I am concerned, I'd definitely rewrite stuff I have touched in order to take advantage of this. |
Hm, it seems that we don't log a warning if at least one bean matches. So maybe it would be more meaningful to only emit a warning for |
- only if Instance#get(), InjectableInstance#getHandle() and ArcContainer.instance() is called - added InjectableInstance.orElse() and InjectableInstance.orNull() - resolves quarkusio#18345
- only if Instance#get(), InjectableInstance#getHandle() and ArcContainer.instance() is called - added InjectableInstance.orElse() and InjectableInstance.orNull() - resolves quarkusio#18345
- only if Instance#get(), InjectableInstance#getHandle() and ArcContainer.instance() is called - added InjectableInstance.orElse() and InjectableInstance.orNull() - resolves quarkusio#18345
- only if Instance#get(), InjectableInstance#getHandle() and ArcContainer.instance() is called - added InjectableInstance.orElse() and InjectableInstance.orNull() - resolves quarkusio#18345
- only if Instance#get(), InjectableInstance#getHandle() and ArcContainer.instance() is called - added InjectableInstance.orElse() and InjectableInstance.orNull() - resolves quarkusio#18345
- only if Instance#get(), InjectableInstance#getHandle() and ArcContainer.instance() is called - added InjectableInstance.orElse() and InjectableInstance.orNull() - resolves quarkusio#18345
- only if Instance#get(), InjectableInstance#getHandle() and ArcContainer.instance() is called - added InjectableInstance.orElse() and InjectableInstance.orNull() - resolves quarkusio#18345
@mkouba I see you updated the example you mentioned above. But I assume your comment about us needing to rewrite the rest of the instances still applies? |
Well, any occurence of |
Great, thanks |
Many thanks for fixing this :) Regarding the loading getting triggered when our extensions aren't careful about it - would there be a way to verify noone is doing that? |
No way I'm aware of. Also keep in mind that it's perfectly legal to call those methods above at any time. So from my point of view it's more like a best effort. |
Right, I understand it's "legal" for end users to trigger this; I'm indeed thinking about a best effort tool that we could use to spot obvious misunderstandings leveraging our extensive testsuite. For example we could have a system property that makes this legal operation throw an exception and set this in our testsuite to spot extensions needing some polishing; also works to spot regressions in the future so we can sleep well without having to review all PRs for this pattern :) But I'm not sure if that would be practical; I suppose there might be extensions which we don't want to patch for this at this time, so at least we'd nee a flag set globally but also allow a particular module to opt-out. Perhaps that's too much work, but I'm wondering. |
Yes, I think that it's too much. Keep in mind that we have |
Seems like we have a lot of |
But that's ok if we expect the bean to be available. It's suboptimal if we know that a bean might not be available. |
Ah, thanks for the clarification, it makes a big difference. |
- only if Instance#get(), InjectableInstance#getHandle() and ArcContainer.instance() is called - added InjectableInstance.orElse() and InjectableInstance.orNull() - resolves quarkusio#18345
- only if Instance#get(), InjectableInstance#getHandle() and ArcContainer.instance() is called - added InjectableInstance.orElse() and InjectableInstance.orNull() - resolves quarkusio#18345
- only if Instance#get(), InjectableInstance#getHandle() and ArcContainer.instance() is called - added InjectableInstance.orElse() and InjectableInstance.orNull() - resolves quarkusio#18345
- only if Instance#get(), InjectableInstance#getHandle() and ArcContainer.instance() is called - added InjectableInstance.orElse() and InjectableInstance.orNull() - resolves quarkusio#18345
Description
When looking at heap dumps of a Quarkus application running in production mode, the retained memory from
io.quarkus.arc.impl.ArcContainerImpl#removedBeans
stands out as being a little high.Considering this information is only needed to throw a more helpful error message if there's ever an error caused by a missing bean, it would be nice to load this information lazily.
Implementation ideas
Essentially we think it should be possible to serialize this information during the build, dump it into a resource, and then only load this if ever such an error is triggered.
The text was updated successfully, but these errors were encountered: