You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Could it make sense to revisit the issue of dispatching coroutines at different priority levels, based on the new Dispatcher Views API? The priority could be tied to the dispatcher view, for example limitedParallelism(parallelism, priority).
The issue of prioritized coroutine dispatching has come up several times before, e.g. #238, #476, #1617.
My use case is sound generation in an Android game, which needs to be as realtime as possible. Currently I use a dedicated thread with elevated thread priority, which seems expensive and not necessarily as realtime as I'd like due to thread switching. A Dispatcher View on top of Dispatchers.Default with a parallelism of 1 and maximized ("realtime") dispatch priority might be a better solution, if it were available. Reimplementing in C is another option here, but I don't want to go there.
The text was updated successfully, but these errors were encountered:
Thanks for the detailed explanation of your use-case!
Unfortunately, such API doesn't seem possible, because priority is not the property of view, but the property of an underlying dispatcher. If the dispatcher doesn't support it, then views won't either.
Integrating priorities into existing dispatchers will be a significant performance hit, both from scheduling latencies and allocation pressure perspective -- for priorities, scheduler has to maintain any kind of concurrent balanced tree/heap/relaxed heap which are not easily optimizable and we are not ready to start working on that.
I would be delighted to see an external implementations though, for example, it could be a custom dispatcher that has the priority mechanism built-in and priorities accepted as part the first argument of dispatch(context: CoroutineContext, block: Runnable) method. Then we can evaluate it and see if kotlinx.coroutines can provide somehow unified access or API to that
Explicitly linking #238, #476, #1617 here so people can find this comment
Could it make sense to revisit the issue of dispatching coroutines at different priority levels, based on the new Dispatcher Views API? The priority could be tied to the dispatcher view, for example
limitedParallelism(parallelism, priority)
.The issue of prioritized coroutine dispatching has come up several times before, e.g. #238, #476, #1617.
My use case is sound generation in an Android game, which needs to be as realtime as possible. Currently I use a dedicated thread with elevated thread priority, which seems expensive and not necessarily as realtime as I'd like due to thread switching. A Dispatcher View on top of Dispatchers.Default with a parallelism of 1 and maximized ("realtime") dispatch priority might be a better solution, if it were available. Reimplementing in C is another option here, but I don't want to go there.
The text was updated successfully, but these errors were encountered: