Looking at graphs produced by our performance testing infrastructure we can see that it consumes a lot of memory and does way too much classpath discovery.
See this help on the gradle build comparing gradle build.
Especially this allocation-tlab graph. Search for KotlinBuildScriptCompiler, you'll see it accounts for 30% of memory allocations, KotlinBuildScriptCompiler.<init> for 20%.
It appears that we visit too much classloaders to infer their classpath, too many times. A lot of this should be avoidable to make configuration time faster. It is definitely the case when one script has no dependencies, parent scope classpath could be reused directly. Something along the lines of this logic that does the exact same thing reusing classpaths would help.
Seems ClasspathUtil is responsible for 20% of the allocations.
Caching the classpath computation should do the trick. Right now it walks the very same class loaders again and again.
Closing as delivered, new version is ~6% faster.
And 25% leaner, nice work!
The performance test infrastructure makes it a joy.
Most helpful comment
And 25% leaner, nice work!