Skip to content

Commit

Permalink
Merge pull request #29006 from loicmathieu/perf-improvements
Browse files Browse the repository at this point in the history
Tiny perf improvements on the QuarkusClassLoader
  • Loading branch information
loicmathieu authored Nov 3, 2022
2 parents ee60a15 + de4adf5 commit da74776
Showing 1 changed file with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static boolean isClassPresentAtRuntime(String className) {
* Indicates if a given resource is present at runtime.
* Can also be used to check if a class is present as a class is just a regular resource.
*
* @param resourceName the path of the resource, for instance {@code path/to/my-resources.properties} for a properties file
* @param resourcePath the path of the resource, for instance {@code path/to/my-resources.properties} for a properties file
* or {@code my/package/MyClass.class} for a class.
*/
public static boolean isResourcePresentAtRuntime(String resourcePath) {
Expand Down Expand Up @@ -211,13 +211,11 @@ public Enumeration<URL> getResources(String unsanitisedName, boolean parentAlrea
for (ClassLoaderEventListener l : classLoaderEventListeners) {
l.enumeratingResourceURLs(unsanitisedName, this.name);
}
boolean endsWithTrailingSlash = unsanitisedName.endsWith("/");
ClassLoaderState state = getState();
String name = sanitizeName(unsanitisedName);
//for resources banned means that we don't delegate to the parent, as there can be multiple resources
//for single resources we still respect this
boolean banned = state.bannedResources.contains(name);
Set<URL> resources = new LinkedHashSet<>();

//this is a big of a hack, but is necessary to prevent service leakage
//in some situations (looking at you gradle) the parent can contain the same
Expand All @@ -241,8 +239,10 @@ public Enumeration<URL> getResources(String unsanitisedName, boolean parentAlrea
}
//TODO: in theory resources could have been added in dev mode
//but I don't thing this really matters for this code path
Set<URL> resources = new LinkedHashSet<>();
ClassPathElement[] providers = state.loadableResources.get(name);
if (providers != null) {
boolean endsWithTrailingSlash = unsanitisedName.endsWith("/");
for (ClassPathElement element : providers) {
ClassPathResource res = element.getResource(name);
//if the requested name ends with a trailing / we make sure
Expand Down Expand Up @@ -349,7 +349,6 @@ public URL getResource(String unsanitisedName) {
for (ClassLoaderEventListener l : classLoaderEventListeners) {
l.gettingURLFromResource(unsanitisedName, this.name);
}
boolean endsWithTrailingSlash = unsanitisedName.endsWith("/");
String name = sanitizeName(unsanitisedName);
ClassLoaderState state = getState();
if (state.bannedResources.contains(name)) {
Expand All @@ -358,6 +357,7 @@ public URL getResource(String unsanitisedName) {
//TODO: because of dev mode we iterate, to see if any resources were added
//not for .class files though, adding them causes a restart
//this is very important for bytebuddy performance
boolean endsWithTrailingSlash = unsanitisedName.endsWith("/");
if (name.endsWith(".class") && !endsWithTrailingSlash) {
ClassPathElement[] providers = state.loadableResources.get(name);
if (providers != null) {
Expand Down Expand Up @@ -449,9 +449,6 @@ protected Class<?> findClass(String moduleName, String name) {

@Override
public Class<?> loadClass(String name) throws ClassNotFoundException {
for (ClassLoaderEventListener l : classLoaderEventListeners) {
l.loadClass(name, this.name);
}
return loadClass(name, false);
}

Expand All @@ -474,10 +471,10 @@ protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundE
return c;
}
String resourceName = sanitizeName(name).replace('.', '/') + ".class";
boolean parentFirst = parentFirst(resourceName, state);
if (state.bannedResources.contains(resourceName)) {
throw new ClassNotFoundException(name);
}
boolean parentFirst = parentFirst(resourceName, state);
if (parentFirst) {
try {
return parent.loadClass(name);
Expand Down

0 comments on commit da74776

Please sign in to comment.