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 */
|
/* Make sure that all afterEvaluate blocks from the AndroidPlugin get scheduled first */
|
||||||
val isDispatched = AtomicBoolean(false)
|
val isDispatched = AtomicBoolean(false)
|
||||||
androidPluginIds.forEach { androidPluginId ->
|
|
||||||
pluginManager.withPlugin(androidPluginId) {
|
fun isAndroidPluginApplied(): Boolean =
|
||||||
if (!isDispatched.getAndSet(true)) {
|
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() }
|
afterEvaluate { fn() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user