Skip to content

Provide suspendAtomicCancellableCoroutineReusable primitive, high-per… #596

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
wants to merge 6 commits into from

Conversation

qwwdfsad
Copy link
Collaborator

…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

elizarov and others added 3 commits September 19, 2018 18:37
* Uses Kotlin version 1.3-M2
* Uses Kotlin/Native version 0.9
* Replace SuccessOrFailure with Result
* Replace buildSequence and buildIterator with sequence and iterator
* Apply @BuilderInference on all builders (including extension methods to workaround inference bug)
…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 Author

Crazy idea: get rid of _reusableCancellableContinuation and turn resumeMode to Any with following states:

  1. resumeMode is Int && resumeMode >= 0. It's just a mode.
  2. resumeMode is Int && resumeMode < 0. Actual mode is -resumeMode and - indicates sealed reusability. (one may notice that MODE_ATOMIC_DEFAULT is zero, but it can easily be mitigated with shifting all modes).
  3. resumeMode is CancellableContinuation, then actual mode is (resumeMode as CancellableContinuation).resumeMode. If cancellation is currently used, we can safely mutate its resumeMode if we will restore it later in suspendAtomicCancellableCoroutineReusable

@qwwdfsad qwwdfsad requested a review from elizarov September 21, 2018 16:55
qwwdfsad and others added 3 commits September 21, 2018 19:58
* Extracted getOrCreateCancellableContinuation from
  suspendAtomicCancellableCoroutineReusable
* Separate NON_REUSABLE constant for readability
* Make non-reusable only on idempotent tryResume
@elizarov elizarov force-pushed the eap13 branch 4 times, most recently from 9a415e0 to d3ac541 Compare September 29, 2018 13:34
@qwwdfsad qwwdfsad force-pushed the eap13 branch 4 times, most recently from 00dad2d to 0950dfa Compare October 8, 2018 16:05
@qwwdfsad qwwdfsad closed this Oct 24, 2018
@qwwdfsad qwwdfsad deleted the cached-cancellability branch October 2, 2019 08:56
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