-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Avoid calling ServiceLoader twice with same class loader #5903
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
base: master
Are you sure you want to change the base?
Conversation
The ServiceLoader goes through all the jars to find its files and it seems like a good idea to avoid doing it twice for the same class loader. This is somehow related to the work we are doing in Quarkus for Leyden.
|
FYI @geoand |
|
I'm interested in having this backported to 4.x for current Quarkus. |
|
BTW, just to clarify: in my case, it was for a service file that didn't exist so we were going through all the calls as the list was empty. |
…ss<T>, java.lang.ClassLoader) For readability Signed-off-by: Thomas Segismont <tsegismont@gmail.com>
tsegismont
left a comment
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.
Thanks @gsmet
I pushed a commit to simplify the method for readability. Tell me what you think
@gsmet fine with me. When this one is merged, can you send PRs to the Please note that, in Vert.x 5, this class has moved to an impl package (not visible in a modular Java app) |
|
So it all depends on what you want to do. My initial PR didn't change the logic. Your commit changes the logic right? If you enforce a CL, we don't try to fallback to the |
Right
Yes, it does. I think we messed-up somewhere, and started to try loading factories twice even when the user provided a specific classloader. As the comment at the bottom suggests, we should try again only when the first attempt was with the TCCL. The original change is #1058 |
|
But the TCCL might be what loaded |
|
If you invoke |
|
Yeah, I understand that. But why make the TCCL case worse than with my change? I don't understand the rationale? |
|
I'm specifically talking about having |
…eHelper's CL Saves the cost of scanning the classpath again Signed-off-by: Thomas Segismont <tsegismont@gmail.com>
|
is that possible to get a test for this ? |
|
As discussed off-list, the code in The original intent of this PR is to avoid loading factories twice when the TCCL happens to be the same as the |
If we had a mocking lib in the test scope, we could verify
Otherwise, I don't know how we can check what our code does with the classloader |
|
I think we already have structure for this to verify loading with a classloader |
I see that in @gsmet can you share a stacktrace or flamegraph that shows how the classloader was searched several times so that we can intercept the right methods and verify assumptions? |
Motivation:
The ServiceLoader goes through all the jars to find its files and it seems like a good idea to avoid doing it twice for the same class loader.
This is somehow related to the work we are doing in Quarkus for Leyden.
Conformance:
You should have signed the Eclipse Contributor Agreement as explained in https://github.com/eclipse/vert.x/blob/master/CONTRIBUTING.md
Please also make sure you adhere to the code style guidelines: https://github.com/vert-x3/wiki/wiki/Vert.x-code-style-guidelines
I think I have signed the ECA already to work on Bean Validation.