diff options
author | 2024-12-06 16:42:55 -0500 | |
---|---|---|
committer | 2024-12-09 13:25:06 -0500 | |
commit | 2b08d466d90c8a0b1483e7a5389d7228da1718a1 (patch) | |
tree | 6a9786ae7c9e1734d52705ad18057a4b22349e7d | |
parent | 0855f3edc72fcf3cea17d3482a3c18b3ac8ab326 (diff) |
[kairos] reduce coroutine usage in buildscope
small optimization to bypass unnecessary coroutine overhead
Flag: EXEMPT unused
Test: atest kairos-tests
Change-Id: I82c2f1d4899b3d4cdfda02c9d02375b382abb4b3
-rw-r--r-- | packages/SystemUI/utils/kairos/src/com/android/systemui/kairos/internal/BuildScopeImpl.kt | 11 |
1 files changed, 3 insertions, 8 deletions
diff --git a/packages/SystemUI/utils/kairos/src/com/android/systemui/kairos/internal/BuildScopeImpl.kt b/packages/SystemUI/utils/kairos/src/com/android/systemui/kairos/internal/BuildScopeImpl.kt index 90f1aea3e42f..87897d876967 100644 --- a/packages/SystemUI/utils/kairos/src/com/android/systemui/kairos/internal/BuildScopeImpl.kt +++ b/packages/SystemUI/utils/kairos/src/com/android/systemui/kairos/internal/BuildScopeImpl.kt @@ -34,7 +34,6 @@ import com.android.systemui.kairos.TFlowInit import com.android.systemui.kairos.groupByKey import com.android.systemui.kairos.init import com.android.systemui.kairos.internal.util.childScope -import com.android.systemui.kairos.internal.util.launchOnCancel import com.android.systemui.kairos.internal.util.mapValuesParallel import com.android.systemui.kairos.launchEffect import com.android.systemui.kairos.util.Just @@ -49,7 +48,6 @@ import kotlin.coroutines.EmptyCoroutineContext import kotlin.coroutines.startCoroutine import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.CompletableJob -import kotlinx.coroutines.CoroutineName import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Deferred import kotlinx.coroutines.Job @@ -164,7 +162,7 @@ internal class BuildScopeImpl(val stateScope: StateScopeImpl, val coroutineScope val subRef = AtomicReference<Maybe<Output<A>>>(null) val childScope = coroutineScope.childScope() // When our scope is cancelled, deactivate this observer. - childScope.launchOnCancel(CoroutineName("TFlow.observeEffect")) { + childScope.coroutineContext.job.invokeOnCompletion { subRef.getAndSet(None)?.let { output -> if (output is Just) { @Suppress("DeferredResultUnused") @@ -215,7 +213,7 @@ internal class BuildScopeImpl(val stateScope: StateScopeImpl, val coroutineScope } else if (needsEval) { outputNode.schedule(evalScope = stateScope.evalScope) } - } ?: childScope.cancel() + } ?: run { childScope.cancel() } } return childScope.coroutineContext.job } @@ -229,10 +227,7 @@ internal class BuildScopeImpl(val stateScope: StateScopeImpl, val coroutineScope "mapBuild", mapImpl({ init.connect(evalScope = this) }) { spec -> reenterBuildScope(outerScope = this@BuildScopeImpl, childScope) - .runInBuildScope { - val (result, _) = asyncScope { transform(spec) } - result.get() - } + .runInBuildScope { transform(spec) } } .cached(), ) |