Skip to content

Provide high-performance and reusable CancellableContinuation implementation #534

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

Closed
elizarov opened this issue Sep 7, 2018 · 1 comment
Assignees

Comments

@elizarov
Copy link
Contributor

elizarov commented Sep 7, 2018

Consider the following code that reads some bytes in a loop:

suspend fun foo() {
   while (true) {
       val bytes = readBytes(buf) // suspending
       if (bytes < 0) break
   }
}

where readBytes is written via suspendCancellableCoroutine. The problem is that each readBytes invocation allocates a new CancellableContinuationImpl object and some auxiliary ones to track parent's cancellation. This is unacceptable for high-performance IO code and a standard solution need to be provided for that. For 1.0 release we are looking for an experimental implementation of such an API that relies on new feature in 1.3 coroutines: ContinuationInterceptor.releaseInterceptedContinuation.

qwwdfsad added a commit that referenced this issue Sep 21, 2018
…formance intrinsic which allows to reuse cancellation machinery and opens the way to garbage-free channels:

  * Make AbstractContinuation reusable
  * Add additional field to DispatchedContinuation to cache cancellable continuation
  * Use suspendAtomicCancellableCoroutineReusable in channels (+15% of performance on ping-pong)
  * Detect calls to tryResume and forbid cancellation reusing in order to make channels work with selects
  * Fix benchmarks on 1.3

Fixes #534
@qwwdfsad
Copy link
Collaborator

Will be fixed in 1.3.3 by #1534

@qwwdfsad qwwdfsad self-assigned this Sep 25, 2019
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