Does anyone know if `foo { bar(it) }` has a perfor...
# compiler
r
Does anyone know if
foo { bar(it) }
has a performance cost over
foo(bar)
allocating an extra lambda? If so is this something the Kotlin compiler already optimizes for?
u
There's no such optimization,
foo { bar(it) }
will create an extra lambda
r
Thanks @udalov for confirming
d
And
foo(::bar)
, if that's what you actually had in mind, will create an extra callable reference. At the same time, if
{ bar(it) }
has trivial (empty) closure, compiler will generate a single static instance for lambda, and will reuse it. So, it's a bit more complex.
👍 3