-
Couldn't load subscription status.
- Fork 1.9k
Open
Labels
Description
Some coroutines are very likely to get cancelled a short time after they are launched, making the CancellationException stacktrace calculation into a large portion of the runtime.
Examples:
- This was shared with us: https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/gestures/MouseWheelScrollable.kt;l=266;drc=640651fd5298977dc63c0d11f646fb4b219a5683
- Launching several coroutines to race with one another (Provide an API to race coroutines ("losers" are cancelled) #2867) if one operation (for example, accessing a cache) is very short-lived.
This calls for an API that allows not populating the stacktraces but instead using a CancellationException object created in advance.
Options:
- Cancel-site:
cancelalready can accept customCancellationExceptionvariants, andwithTimeout*could also be parameterized to allow this. - Throw-site:
suspendCancellableContinuationcould react to a specialCoroutineContextElementspecifying that the cancellation exception of the suspended coroutine itself does not need to be instantiated.