Skip to content

Conversation

@kaseken
Copy link

@kaseken kaseken commented Jun 14, 2025

Problem

The documentation for Dispatchers.IO appears to be misleading.

Specifically, it suggests that the kotlinx.coroutines.io.parallelism system property limits the number of threads, when in fact:

  • The kotlinx.coroutines.io.parallelism property controls the parallelism limit, not the maximum thread count.
  • The actual thread pool backing Dispatchers.IO can grow up to MAX_POOL_SIZE, which defaults to CoroutineScheduler.MAX_SUPPORTED_POOL_SIZE (2^21 - 2 = 2,097,150 threads).

Proposal

Update the comment to clarify that kotlinx.coroutines.io.parallelism controls parallelism (i.e., the number of concurrently scheduled tasks), not the actual number of threads used by the underlying thread pool.

- Clarify that kotlinx.coroutines.io.parallelism controls parallelism rather than thread count.
@dkhalanskyjb
Copy link
Collaborator

Nope, it's accurate.

The actual thread pool backing Dispatchers.IO can grow up to MAX_POOL_SIZE

It will only do that if these threads are needed to provide the required parallelism. You won't suddenly see MAX_POOL_SIZE threads in your system if you are only using Dispatchers.IO without other views of the same underlying pool.

@kaseken kaseken closed this Jun 16, 2025
@kaseken kaseken deleted the fix-misleading-doc-comment-for-dispatchers-io branch June 16, 2025 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants