Shame. On the upside, it’s all perf wins optimizin...
# announcements
p
Shame. On the upside, it’s all perf wins optimizing code from there 😄
k
What allocation is this about?
this one
it’s not a biggie by itself, it just makes me wonder whether to audit the codebase for others
k
I'm still pretty lost, are you talking about repeated uses if the same code as a lambda or something like that?
p
So IO could be doing one extra allocation per mapFilter call, which isn’t too much of an issue
at scale, if every call to every IO through the codebase adds an allocation or a couple, they could add up to something meaningful
not something that’ll get you to UI jank on an Android app but you know, something noticeable that’s just free perf
r
I think what Paco means that if the compiler finds this expression
map { f(it) }
could optimice it to just
map(f)
not incurring in an additional lambda allocation.
👍 1
p
^^^^^ that
r
unless it already does that which I don't know.
k
Oh where
f
is another lambda/function parameter. I was thinking of it as a real function 🤦‍♂️
r
no it's just whatever map or any function for that matter takes as argument
applying
it
to it seems to have a cost where it's obvious it could be optimized to just pass the reference to the method
I'm not sure if JIT or Kotlin already tries to optimize these cases, so also looking forward to finding out
d
What allocation though? As in it puts an extra variable on the stack? What?? If I got this right, I'd say this investigation is a waste of your time. No offense.
Unless
map
is called on a
Sequence
in which case it's not inlined of course.
d
I'm a bit confused. I suppose that most maps are inline, in which case it's moot, but in this case the particular map wasn't?
p
we have plenty of non-inlined maps in arrow because they're suspended constructs
maps for list, map, set, and other collections are eager and it could make sense to inline them if you're not concerned about bycode bloat
maps for observable, IO, even mapping functions themselves require capturing the lambda parameter in a data structure to execute it later
so you do pay for that extra allocation