From d5bdf6f14dd4d8db5d08531caf09fadae0806c13 Mon Sep 17 00:00:00 2001 From: seyoungcho2 Date: Tue, 25 Mar 2025 07:22:03 +0900 Subject: [PATCH] Improve performance of SharingStarted.StartedLazily by changing flow to unsafeFlow --- kotlinx-coroutines-core/common/src/flow/SharingStarted.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kotlinx-coroutines-core/common/src/flow/SharingStarted.kt b/kotlinx-coroutines-core/common/src/flow/SharingStarted.kt index b9b73603c4..e1f2051e60 100644 --- a/kotlinx-coroutines-core/common/src/flow/SharingStarted.kt +++ b/kotlinx-coroutines-core/common/src/flow/SharingStarted.kt @@ -1,6 +1,7 @@ package kotlinx.coroutines.flow import kotlinx.coroutines.* +import kotlinx.coroutines.flow.internal.unsafeFlow import kotlinx.coroutines.internal.IgnoreJreRequirement import kotlin.time.* @@ -146,7 +147,7 @@ private class StartedEagerly : SharingStarted { } private class StartedLazily : SharingStarted { - override fun command(subscriptionCount: StateFlow): Flow = flow { + override fun command(subscriptionCount: StateFlow): Flow = unsafeFlow { var started = false subscriptionCount.collect { count -> if (count > 0 && !started) {