Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return UnlimitedIoScheduler instance for Dispatchers.IO.limitedParallelism(Int.MAX_VALUE) #3442

Closed
dovchinnikov opened this issue Sep 7, 2022 · 2 comments

Comments

@dovchinnikov
Copy link
Contributor

Don't wrap it into LimitedDispatcher unnecessarily.

@qwwdfsad
Copy link
Member

qwwdfsad commented Sep 8, 2022

Do we have any evidence that LimitedDispatcher overhead is non-eglible or is it rather a "nice to have" enhancement?

@dovchinnikov
Copy link
Contributor Author

I didn't do any measurements, but I'm 100% sure that doing nothing is faster than whatever LimitedDispatcher is doing.

dovchinnikov added a commit to dovchinnikov/kotlinx.coroutines that referenced this issue Dec 28, 2022
…n#3442)

`LimitedDispatcher.limitedParallelism` returns `this` if requested parallelism is greater or equal
to the own parallelism of the said `LimitedDispatcher`. `UnlimitedIoScheduler` has parallelism effectively set
to `Int.MAX_VALUE`, so `parallelism >= this.parallelism` check folds into `parallelism == Int.MAX_VALUE`.

Before the change `LimitedDispatcher(Int.MAX_VALUE)` was returned. While it does work as expected, any submitted task
goes through its queue and `Int.MAX_VALUE` number of workers. The change allows to eliminate the `LimitedDispatcher`
instance and its queue in this extreme case.
dovchinnikov added a commit to dovchinnikov/kotlinx.coroutines that referenced this issue Dec 28, 2022
…elism >= core pool size (Kotlin#3442)

`LimitedDispatcher.limitedParallelism` returns `this` if requested parallelism is greater or equal
to the own parallelism of the said `LimitedDispatcher`. `DefaultScheduler` has parallelism effectively set
to `CORE_POOL_SIZE`.

Before the change `LimitedDispatcher(parallelism)` was returned. While it does work as expected, any submitted task
goes through its queue and `parallelism` number of workers. The change allows to eliminate the `LimitedDispatcher`
instance and its queue in case the requested parallelism is greater or equal to `CORE_POOL_SIZE`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants