gradle / kotlin-dsl-samples

Samples builds using the Gradle Kotlin DSL
https://gradle.org/kotlin/
Other
3.71k stars 433 forks source link

KT-24668 - Kotlin DSL 3-4x slower than Groovy DSL on FIRST USE on many simple projects build #902

Open eskatos opened 6 years ago

eskatos commented 6 years ago

Groovy DSL ~18s scenario: first use of largeJavaMultiProject template: largeJavaMultiProject performance test results

Kotlin DSL ~75s scenario: first use of largeJavaMultiProjectKotlinDsl template: largeJavaMultiProjectKotlinDsl performance test results

Both with:

The compilation of the 500 build scripts of the example build by the Kotlin compiler dominates wall clock. Note that script compilation is not parallelized in Kotlin nor Groovy.

See the upstream KT-24668 investigation issue.

JLLeitschuh commented 6 years ago

Is this also true with importing into the IntelliJ?

hansd commented 6 years ago

It might be helpful to do a similar measurement with the following parameters:

eskatos commented 6 years ago

Ways to improve the situation include:

joshuadeguzman commented 5 years ago

Hi @eskatos , I am curious if this issue was already resolved?

eskatos commented 5 years ago

@joshuadeguzman first use is still that slower, dominated by the Kotlin compiler. It could still benefit from parallel compilation and incremental changes to build logic could still benefit from compilation avoidance as linked above.

joshuadeguzman commented 5 years ago

Great! Thank you for the confirmation @eskatos .

kaushalyap commented 5 years ago

@eskatos Any plans to get this done (seems repo is not active)? I think this may be the reason Android Studio Kotlin DSL support lagging behind?

eskatos commented 5 years ago

We have two performance tests running respectively the Groovy DSL and the Kotlin DSL on the same large project for a first use use case:

Those links (use Login as guest) are for current master branch of Gradle that is ~6.0.

There we can see that the Kotlin DSL build is still ~3x slower than the Groovy DSL build on first use.

Then, on repeated use without changes, this performance test compares Groovy DSL vs. Kotlin DSL:

In that use case, we can see that the Kotlin DSL build is ~10% slower than the Groovy DSL build.

That's it for the current state of affairs.

Now on how to make the situation better, my https://github.com/gradle/kotlin-dsl-samples/issues/902#issuecomment-501672404 above still stands.

In any case the best bet to make the situation better across all use cases would be for the Kotlin compiler itself to get faster, this is in JetBrains hands.

Otherwise, compiling the scripts in parallel https://github.com/gradle/gradle/issues/9225 could also make all use cases faster (most probably benefiting to the Groovy DSL too 😃) but this isn't trivial and will require deep changes in Gradle. IOW it'll take time.

The most probable next step is some form of compilation avoidance for Kotlin DSL scripts https://github.com/gradle/gradle/issues/9224 that will make the change in build logic use case faster (not scheduled for now but I'll push for it).

I hope the above clarifies the situation.

kaushalyap commented 5 years ago

@eskatos Thanks for the detailed response!

mochadwi commented 4 years ago

thanks for the detailed explanations @eskatos & an alternative workaround

EDITED:

  • 201/KT-24668 Optimize Kotlin compiler context reuse