I have a project that's ~360k lines of Kotlin code...
# compiler
s
I have a project that's ~360k lines of Kotlin code (~20k written by humans ~340k generated) and locally it takes about 8 minutes to run (the compileKotlin step, I'm using Gradle, laptop is a macbook w/ 3.1 GHz Quad-Core Intel Core i7 and I know this result is not particularly scientific) I was wondering — does anyone know whether this is around the expected runtime given this much kotlin? Are there particularly expensive types of things to compile? Any way I could profile it? Compile times are getting painful for folks so anything I can do to relieve some of this will be helpful if there are suggestions.
d
Hello Main problem in current compiler performance are bad architecture decisions which were made at start of compiler development. We know about this problems and completely rewrite compiler keeping performance at the first place. New compiler us not ready yet, but it already shows great performance comparing to our one (it several times faster).
Unfortunately new compiler won't be released at least for year, so there is no fast decision of your problem.
Can you describe, how your project is organized? Do you split code for different modules, do you use incremental compilation?
r
As far as I know implicit return type of function could dramatically slow down compilation speed so probably specifying them explicitly might help a bit.
1
s
@dmitriy.novozhilov Generally speaking the code is modularized but what I'm describing is all within a single module though splitting them is something we're exploring. We're using Kotlin 1.3.72 w/ Gradle so I believe that means incremental compilation is enabled by default and I see the KotlinCompilerDaemon spin up during builds so we use that as well (though I'm not sure if that's a configurable option). @Roman Artemev [JB] — Interesting, I'll look at our generated functions to see whether or not they're specifying return types and specify them if not
d
Unit of incremental compilation in gradle is one module, so you can speed up your build by splitting auto generated code (which I believe changes rarely) and user code into different modules. It's best option I can recommend for gradle build
s
yeah, the code is a bit tangled but let me look at how much it can be modularized
Other than modularizing / trying to explicitly specify function return types, any other tips? Can't wait for the new compiler by the way! I know it's not going to be stable for some time but out of curiosity, will it be possible to enable it experimentally just to play with in 1.4 or 1.5 @dmitriy.novozhilov?
d
You can enable compilation with FIR using
-Xuse-fir
compiler flag
s
https://kotlinlang.slack.com/archives/C7L3JB43G/p1596276900402200?thread_ts=1596237765.398700&cid=C7L3JB43G Sorry to resurrect an old thread but @Roman Artemev [JB] does this include functions which don't return anything? Would it be better to explicitly specify
Unit
in that case?
Also, is this relevant to lambdas? I.e. should anonymous functions with explicit return types specified be preferred from a compiler performance perspective?
d
does this include functions which don't return anything?
No, because
fun foo() {}
and
fun foo(): Unit {}
are equal declarations for compiler, missing
: Unit
here is just syntax sugar
Also, is this relevant to lambdas? I.e. should anonymous functions with explicit return types specified be preferred from a compiler performance perspective?
Each implicit type (missing return type, not declared type of property, not specified type type arguments of call, etc) increase amount of work for compiler, because those types should be inferred. If you are generating code then you can try explicitly declare as much types as possible