Hi all, I have an Android app where I am tracking ...
# android-architecture
r
Hi all, I have an Android app where I am tracking selection counts for roughly 50 items. My plan was to track selections in a RoomDB and give each item have its own flow query that emits the selection count when it changes. My question that I can not find any info on, is there a suggested max # of flows that can be open concurrently with room or would that approach work ok?
u
is it necessary to have each selection in its own query ? I would have thought that a
State
data class of some sort would suffice if all you are doing is incrementing a counter
r
I actually had it in a map, even a state class is a lot to maintain for 50 items. The 1 flow per item is way simpler. I just have no idea if 50 flows open is too many or if they are the same as coroutines and it is designed to have 1000+ open concurrently
u
50 items is a lot regardless of method employed. The 1 query per flow is just moving that overhead to maintaining 50 different queries vs a data class. The data class has the benefit of centralisation. Your best bet is to do some benchmarking, and if the increments are manually triggered via enduser then perhaps the overhead is not so bad. If you are willing to reveal more about your domain, then maybe we can help you consider alternative design patterns
r
will brainstorm some more here, might circle back. Still trying to figure out if there is a suggested max # similar to how they say you can launch 1000s of coroutines. Benchmarking will be good but know there are potential edges even if benchmarks are ok
u
Predicting overhead is per case. We can give you generic guidelines but ultimately you will need to benchmark your code base to gauge any performance degradations. The general principle is threads have a lot of overhead, coroutines don't - they are much lighter, are not cpu bound like threads, and are a lot like the actor model minus the messaging. So theoretically, 50 coroutines isn't that expensive but we must also account for what you are doing with them.