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

Paddy O'Brien

01/20/2023, 9:09 PM
Does KMM have anything like Swift’s
-Xfrontend -debug-time-function-bodies
or support Clang’s
-ftime-report
or
-ftime-trace
Looking to get granular information on our compile times
Hoping for more granularity than the build reports added in 1.7 https://blog.jetbrains.com/kotlin/2022/06/introducing-kotlin-build-reports/
d

dmitriy.novozhilov

01/23/2023, 9:18 AM
Kotlinc does not collect such statistics, because of several reasons: • Each function is analyzed by compiler multiple times on different passes, so there is no single place where we can insert counters. And time of each pass is relatively small (for one function), so adding counters may affect real execution time • It's hard to implement, because in some cases compiler analyses one function during analysis of some other function. Consider this case:
Copy code
fun foo() = bar()
fun bar() = baz()
fun baz() = 10
During analysis of function
foo
compiler needs to know type of function
bar
, which implies that it need to actually analyze
bar
. And same goes for
bar
and
baz
. So to carefully count time we will need to implement logic for distinguish such jumps between functions • All such measurements won't be accurate anyway (at least at frontend), because analysis of body can invoke number of different heavy calculations, which will be cached after first computation
Copy code
import java.lang.Thread

fun foo() {
    Thread().start()
}

fun bar() {
    // 100 lines of code
    Thread().start()
}
E.g. in this case real time of analysis of function
foo
can be ten times bigger than function
bar
(despite the fact that
bar
is actually bigger than
foo
). The thing is there is a access to class
java.lang.Thread
, which came from some
.jar
, so when compiler tries to resolve such class it needs to scan all
.jar
, find one which contains required class, and deserialize it from
.class
file into some representation which compiler is using. And after it was done for some class compiler saves the result and then reuses it
p

Paddy O'Brien

01/24/2023, 7:06 PM
Thanks for the explanation.
6 Views