KT-50509: Optimize the performance of whenEvaluated { ... } wrapper
The Gradle API `pluginManager.withPlugin(id) { ... }` turned out to have
a significant performance footprint due to operations on underlying
immutable collections.
We can replace calls to `withPlugin` with checks of `hasPlugin` running
on each applied plugin.
Issue #KT-50509 Verification pending
This commit is contained in:
+11
-3
@@ -217,9 +217,17 @@ internal fun <T> Project.whenEvaluated(fn: Project.() -> T) {
|
||||
|
||||
/* Make sure that all afterEvaluate blocks from the AndroidPlugin get scheduled first */
|
||||
val isDispatched = AtomicBoolean(false)
|
||||
androidPluginIds.forEach { androidPluginId ->
|
||||
pluginManager.withPlugin(androidPluginId) {
|
||||
if (!isDispatched.getAndSet(true)) {
|
||||
|
||||
fun isAndroidPluginApplied(): Boolean =
|
||||
androidPluginIds.any { pluginManager.hasPlugin(it) }
|
||||
|
||||
if (isAndroidPluginApplied()) {
|
||||
if (!isDispatched.getAndSet(true)) {
|
||||
afterEvaluate { fn() }
|
||||
}
|
||||
} else {
|
||||
plugins.all {
|
||||
if (!isDispatched.get() && isAndroidPluginApplied() && !isDispatched.getAndSet(true)) {
|
||||
afterEvaluate { fn() }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user