I was thinking about `foo.let(Bar::method)` vs `fo...
# announcements
d
I was thinking about
foo.let(Bar::method)
vs
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
.let(func::ref)
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).
z
FYI #C7L3JB43G
k
that's not how you micro benchmark
d
If a file is recompiled a hundred times on an otherwise idle system, and another file goes through the same procedure, and both files compile to the same bytecode, and there is a consistent difference in time, then that difference is real. I've never called it a micro benchmark, and it was enough for exploring my curiosity.
k
What did you pick as your bar.method?
d
The same as bar::method.