Slackbot
01/19/2024, 9:21 AMVampire
01/19/2024, 10:58 AMclassLoaderIsolation.
Even if you stay within one task instance and ensure the tasks are run sequentially it always uses a fresh class loader.
I tried with
workQueue.submit(FooAction::class) {}
workQueue.await()
workQueue.submit(FooAction::class) {}
workQueue.await()
Without the awaits, the tasks are run in parallel, so couldn't be reused anyway.
With processIsolation it is different as spinning up worker processes is much more costly, so there they have deduplication.
With above test code, even multiple instances of the task where each has a different workQueue reuse the worker process as it is free by the waiting.
Without the waiting multiple are created to run in parallel, but those reused.Vampire
01/19/2024, 10:59 AMVampire
01/19/2024, 11:01 AMval fooConfiguration by configurations.dependencyScope("foo")
dependencies {
fooConfiguration("commons-io:commons-io:+")
}
val fooClasspathConfiguration = configurations.resolvable("fooClasspath") {
extendsFrom(fooConfiguration)
}
abstract class FooAction : WorkAction<WorkParameters.None> {
override fun execute() {
val classLoader = Class.forName("org.apache.commons.io.Charsets").classLoader
println("classLoader: ${System.identityHashCode(classLoader)} / $classLoader")
}
}
abstract class FooTask : DefaultTask() {
@get:Inject
abstract val workerExecutor: WorkerExecutor
@TaskAction
fun foo() {
println("workerExecutor: ${System.identityHashCode(workerExecutor)} / $workerExecutor")
val workQueue = workerExecutor.classLoaderIsolation {
classpath.from(project.configurations.named("fooClasspath"))
}
println("workQueue: ${System.identityHashCode(workQueue)} / $workQueue")
workQueue.submit(FooAction::class) {}
workQueue.await()
workQueue.submit(FooAction::class) {}
workQueue.await()
}
}
val foo by tasks.registering(FooTask::class)
val bar by tasks.registering(FooTask::class)
Then kick off gw foo bar.
Only things I changed are await or not await and classLoaderIsolation vs. processIsolation.Martin
01/19/2024, 2:59 PMyou would first to request this as feature and then it hopefully would work like with the process isolation without the need to manually share the work queue.I see, yep having that dedup made automagically would be the best indeed 👍 . I'll try to benchmark the cost, make sure that's a real problem before opening an issue.