https://kotlinlang.org logo
Title
l

louiscad

06/07/2019, 9:04 AM
It seems replacement for
flowViaChannel(Channel.CONFLATED) { … }
is
channelFlow<T> { … }.buffer(Channel.CONFLATED)
. Isn't that less efficient as values pass through 2 operators?
e

elizarov

06/07/2019, 9:11 AM
It is the same. Buffer fuses with channelFlow
l

louiscad

06/07/2019, 9:12 AM
Was the intention to decouple buffer from the channel flow?
e

elizarov

06/07/2019, 9:12 AM
Well, decoupling.
API orthogonality to be specific.
So there’s only one operator to configure buffer size or conflation. You can also use conflate() operator as a shortcut.
👌 1
l

louiscad

06/07/2019, 9:14 AM
Oh, good one. Why isn't it inline?
e

elizarov

06/07/2019, 9:14 AM
It?
l

louiscad

06/07/2019, 9:15 AM
conflated()
, which is a shorthand for
buffer(CONFLATED)
, implemented exactly that way.
e

elizarov

06/07/2019, 9:18 AM
It makes no difference to make it inline.
l

louiscad

06/07/2019, 9:23 AM
I have been taught function calls are more expensive than an arithmetic operation, and more expensive than no function call. The Android dev docs mentioned this for years (and maybe still do somewhere). It should make a little difference if R8 is not used. I probably worry too much about it though, and debug performance on that order is certainly insignificant.
r

ribesg

06/07/2019, 9:47 AM
I’ve been taught the same thing. @elizarov are you saying there is actually no difference, or that the difference is so close to 0 that we shouldn’t care?
e

elizarov

06/07/2019, 11:14 AM
You should not care for this particular case.
l

louiscad

06/07/2019, 12:37 PM
Now, I'm thinking about that: If you only every use
conflate()
and never call
buffer
directly in your app (including through dependencies), then the apk might finally be a little smaller as
buffer
could be inlined by R8 into
conflate()
, something that might not have been possible or easy to do for R8 if
conflate()
was inlined.
e

elizarov

06/07/2019, 2:11 PM
Don’t overthink it. All these extra calls happen only during setup of the flow, and do not affect the speed on its subsequent execution which will be transferring far mode data and doing far more calls. If it has some effect, it is of extremely small magnitude to be measurable.