do nested functions have any extra overhead? No, r...
# announcements
a
do nested functions have any extra overhead? No, right?
g
Yes, object will be created, same like for lambda
f
Unless you use
inline
, in which case no object is created.
a
these do not exist
f
That's a different, specific case
It's a
local
inline function
a
ah alright, makes sense
f
Will your function still work not as a local function? i.e. does it use local variables?
a
yeah it uses local variables and I can separate it out into multiple non-local functinos but it gets messy
f
Wait, when you say a
nested
function you don't mean a higher order function do you? you mean a local function?
a
I mean a local function
f
In that case there are no objects created, It's just like a normal function afaik nope that is wrong
a
aight... well that would be nice because making functions like this is really messy https://gist.github.com/andrewgazelka/b11555496e289ced537ad281ecc95280
where the local func would require zero params
oooof
f
It does create an object, but you shouldn't worry about performance too much
a
it is already a computationally expensive function, so yea I agree w/ you
it is not something which is going to be called with high frequency
t
I guess that depends on the platform. For the JVM, a subclass of
Function
will be created just like with lambdas (if the function is non capturing, a single instance of the function is reused, otherwise a new one is created each time the wrapping function is called). For JS, nested functions are natively allowed in JavaScript, so this should not introduce more overhead than the JavaScript way to define nested functions. As for Kotlin Native, I have no idea.
f
I would expect it to be 30 times slower in Kotlin Native like everything else 😂
d
Yeah... K/N is indeed about a magnitude slower...