I was thinking about `foo.let(Bar::method)` vs `fo...
# compiler
I was thinking about
foo.let { Bar.method(it) }
in terms of compiler speed, thinking that the function reference opens up to fewer possibilities compared to a block, and it could have a slight, but measurable compilation speedup if used a lot. Generating a 1000 long file with identical
.let { .. }
and another file with
resulted in
.let { ... }
being consistently slightly faster with 7.125 seconds vs 7.882 seconds. One hypothesis is that the function reference version is transformed to the block version during compilation, perhaps someone here knows more of the compiler internals to pitch in on that. As expected identical byte code is generated in both cases. When I then tried with Kotlin 1.4 M2, it turned out that the
.let { ... }
version had become slower, and has now consistently the exact same compilation speed as the function reference. Which is the reason to why I signed up to this slack ­čÖé Was hoping for the opposite as 1.4 is touted to improve compilation speed (but it's not like it's life or death which style is preferred ­čÖé ).
Hello. Algorithms of resolving callable references and lambdas are very similar so performance of them should be very close. How did you measure these numbers (JMH benchmarks, single compiler run, did you use kotlin compiler daemon)? Also matters did you enable new inference algorithm? It is enabled in 1.4 M2 by default, but disabled in 1.3.xx Performace of new inference almost same as old inference, but sometimes it slighly worse
There was no special work to improve compiler performance in 1.4, but we are working on new compiler frontend which should highly improve comipation speed, but it's not ready to release in 1.4 (and I think in 1.5 too)
I don't know the compiler APIs so this was just a very crude guestimation to satisfy my curiosity using hyperfine tool to call kotlinc enough times to counter for noise. The difference over the execution was small, so with 1.3.72 there was a consistent difference between the syntax versions.
For both 1.3.72 and 1.4 M2 I simply executed via
hyperfine "bin/kotlinc foo.kt"
which runs the command until difference between runs are sane.