Has anyone benchmarked kotlin's SharedFlowImpl?
I'm seeing thread contention on a SharedFlow with several collectors, and a quick peek shows that that emitting & taking values all uses a single central lock per instance (.. and it's `this` which is an antipattern)
https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-core/common/src/flow/SharedFlow.kt#L639-L655
I'm seeing thread contention on a SharedFlow with several collectors, and a quick peek shows that that emitting & taking values all uses a single central lock per instance (.. and it's `this` which is an antipattern)
https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-core/common/src/flow/SharedFlow.kt#L639-L655
Comments
StateFlows are better if you can live with those.
"unfortunately, a single collect scales linearly with the number of collectors existing, use-case (each collector scales linearly -> the total CPU burnt is quadratic)"
https://github.com/Kotlin/kotlinx.coroutines/issues/4030
Simple is fast :)
Folks might want to look into creating cold flow, not sure if it also has the same problems but at least there is a shut off valve.