Comments (8)
The change would only impact under multithreading (--parallel
). The synchronization is still performed, just under different objects, and without threads, the JVM could remove the synchronization on runtime in either case.
I haven't profiled gradle for this scenario, but have seen it in other tools such as PMD (which performed this very change not long ago, see pmd/pmd#101).
Still, the important thing here, is that this is low hanging fruit. VisitableURLClassLoader
is already thread-safe, so the change is literally just adding :
static {
ClassLoader.registerAsParallelCapable();
}
No tests need to be changed / added, since this is part of the JRE, and current tests would detect misbehavior / performance regressions.
I volunteer to submit this as a PR if you think this is taking focus away from the core team.
from gradle.
Hi @jochenberger, thanks for the request.
Can you please expand on why this change is important and concretely explain how this affects your build (e.g. from a user perspective)?
from gradle.
It makes parallel loading/compilation of classes possible. See ClassLoader.loadClass(String, boolean) and ClassLoader.getClassLoadingLock(String). If the ClassLoader isn't parallelCapable, it synchronizes over the this
instead of an object that's tied to the class name.
The change will prevent some unnecessary locking and will make it possible to load classes using multiple threads.
From the ClassLoader
Javadocs:
Class loaders that support concurrent loading of classes are known as parallel capable class loaders and are required to register themselves at their class initialization time by invoking the ClassLoader.registerAsParallelCapable method. Note that the ClassLoader class is registered as parallel capable by default. However, its subclasses still need to register themselves if they are parallel capable.
See URLClassLoader.java for an example.
from gradle.
@jochenberger Ok. I'm really looking for: "In what way and how much would a typical user benefit if we did this change and nothing more?" We want to know if this would affect everybody, or just those running --parallel
and whether the gain is significant enough that we should do this instead of other performance optimizations.
from gradle.
I would have created a PR, but I don't want to be forced to sign a CLA. But I'd appreciate if you did it @jsotuyod.
from gradle.
+1
I've had this on my performance wish list for some time. I'd appreciate if @jsotuyod sends a PR for this.
There is also this Oracle JDK doc about the feature: http://docs.oracle.com/javase/7/docs/technotes/guides/lang/cl-mt.html
from gradle.
However there is a risk in this change. Explained in Recommendations for Multithreaded Custom Class Loaders
Custom class loaders that do not have a history of deadlocks do not require any changes. In particular, you do not need to change custom class loaders that follow the recommended acyclic hierarchical delegation model, that is, delegating first to their parent class. For backward compatibility, the Java SE 7 release continues to lock a class loader object unless it registers as parallel capable.
from gradle.
Fixed via #772
from gradle.
Related Issues (20)
- String version parser for version catalog is inconsistent with rich version parser HOT 2
- allow full locking of a SNAPSHOT HOT 2
- javadoc runs before source code generators HOT 2
- Remove JVM target validation control code in Kotlin DSL HOT 1
- Test using LauncherInterceptor fails when executed with Gradle HOT 1
- Caused by: org.gradle.api.internal.plugins.PluginApplicationException: Failed to apply plugin class 'com.vanniktech.maven.publish.MavenPublishBasePlugin'. HOT 1
- IP: Cannot add listener of type ProjectComponentObservationListener after events have been broadcast.
- Task dependencies not being picked up through inputs HOT 2
- Frequent updates and iterations, with many changes that are unfriendly to novices. Online tutorials are outdated and I don't know how to solve any problems HOT 1
- gradle-8.7, java-22: exception in phase 'semantic analysis HOT 5
- Update Apache Ant to latest version to avoid this CVE: https://nvd.nist.gov/vuln/detail/cve-2020-1945 HOT 2
- Upgrade `jackson-databind` to latest to avoid `CVE-2019-16942` HOT 2
- Update Bouncy castle to latest to avoid CVE-2023-33201 HOT 1
- Gradle task delegation doesn't work for compose-build HOT 1
- Unexpected character: '?' @ line 1, column 1. ?//include ':app' HOT 3
- IPv6 Support by default
- typesafe project accessos fail on gradle sync HOT 6
- kotlin stdlib `kotlin.io.walk` does not register directory content as configuration input HOT 1
- cannot select version HOT 1
- Dependency verification: provide dependencyInsight for the dependency automatically HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gradle.