https://kotlinlang.org logo
#compiler
Title
# compiler
t

Tyler Rockwood

06/21/2022, 7:18 PM
What is the best forum to submit compiler performance problems? Should I just dump stuff in Youtrack? Our entire backend is written in kotlin (~400 files and around of 80k lines of code) and compilation times have degraded significantly over the last 6 months of kotlinc releases and the increase of code in our repo. As context we use Bazel instead of Gradle as our build system - so there is no incremental compilation, we've been splitting our modules into small pieces to allow for Bazel to do compilation avoidance, but it's still not enough. For some concrete numbers we have a 23 line file that has a single object with one function that takes ~6 seconds to compile. Below is the output of one run when I add the
-Xreport-perf
flag to the compiler run.
Copy code
info: PERF: <redacted_module_name>, 1 files (23 lines)
info: PERF: INIT: Compiler initialized in 1758 ms
info: PERF:         ANALYZE    4307 ms       5.340 loc/s
info: PERF:  IR TRANSLATION     289 ms      79.585 loc/s
info: PERF:     IR LOWERING     494 ms      46.559 loc/s
info: PERF:   IR GENERATION     348 ms      66.092 loc/s
info: PERF:        GENERATE     842 ms      27.316 loc/s
info: PERF: GC time for G1 Young Generation is 47 ms, 2 collections
info: PERF: GC time for G1 Old Generation is 0 ms, 0 collections
info: PERF: JIT time is 22892 ms
info: PERF: Find Java class performed 11 times, total time 234 ms
info: PERF: Type info performed 39 times, total time 2214 ms
info: PERF: Call resolve performed 38 times, total time 2116 ms
info: PERF: Binary class from Kotlin file performed 210 times, total time 226 ms
We've tried to turn on
-Xbackend-threads
but that fails due to https://youtrack.jetbrains.com/issue/KT-52824. In general we don't have any compiler plugin ourselves, although Bazel uses
jvm-abi-gen
for better compilation avoidance. Are we just hopeless until K2? I've ran across issues like https://youtrack.jetbrains.com/issue/KT-38101 that performance issues (at least in the analyze phase) are being fixed in K2 (which we can't try in alpha yet because of the missing support for plugins). In the release notes for Kotlin 1.7 there was a section that posted performance numbers and there are current packages getting 1-2K loc/s with the current compiler. Even our largest modules (assuming there is some constant overhead that is making the above example so bad) maxes out at about 100 loc/s (5.8k lines in 5 files taking around 57 seconds). Are the Bazel kotlin rules invoking the compiler incorrectly to lead to such bad performance? I'm happy to talk though the threading model and how the Bazel rules invoke the compiler with someone if that turns out to be the issue.
d

dmitriy.novozhilov

06/21/2022, 7:56 PM
It looks like some performance bug inside frontend (most likely in resolution or inference) The best way to report is YouTrack with some reproducer If your project is not open-source and you won't be able to make anonymous reproducer, you can make an issue private and send as many info as possible
t

Tyler Rockwood

06/21/2022, 7:58 PM
Thanks Dmitriy! Is it acceptable to create a Bazel project or would it be better to try and reproduce with raw kotlinc invocations? EDIT: I guess I'm asking which way is more likely to be looked at if you know
👍 1
d

dmitriy.novozhilov

06/21/2022, 8:01 PM
Bazel project will be enough But if you have time and intention to minimize it it will be great help
👍 1
t

Tyler Rockwood

06/21/2022, 8:02 PM
Awesome thanks. I'll try to throw something together this week and post it into YouTrack
7 Views