Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 93add87c authored by Nicolo' Mazzucato's avatar Nicolo' Mazzucato
Browse files

Add flag to not use the immediate kotlin coroutine dispatcher

We had evidences using the immediate dispatcher might be causing additional work, expecially during "combine", as it was triggered inside the doFrame with intermediate values multiple times instead of once after the frame only.

Bug: 411091082
Test: SysUI boots
Flag: com.android.systemui.do_not_use_immediate_coroutine_dispatcher
Change-Id: I3d6cf46c550b85af666a9e95c94a78b674b25e77
parent 0c4aeff0
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -2241,6 +2241,16 @@ flag {
    is_fixed_read_only: true
}

flag {
    name: "do_not_use_immediate_coroutine_dispatcher"
    namespace: "systemui"
    description: "Uses the Main coroutine dispatcher (not immediate) when enabled"
    bug: "411091082"
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}

flag {
    name: "qs_wifi_config"
    namespace: "desktop_connectivity"
+13 −4
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.util.kotlin

import com.android.systemui.Flags
import com.android.systemui.coroutines.newTracingContext
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Main
@@ -43,12 +44,20 @@ class GlobalCoroutinesModule {
        "Use @Main CoroutineContext instead",
        ReplaceWith("mainCoroutineContext()", "kotlin.coroutines.CoroutineContext"),
    )
    fun mainDispatcher(): CoroutineDispatcher = Dispatchers.Main.immediate
    fun mainDispatcher(): CoroutineDispatcher =
        if (Flags.doNotUseImmediateCoroutineDispatcher()) {
            Dispatchers.Main
        } else {
            Dispatchers.Main.immediate
        }

    @Provides
    @Singleton
    @Main
    fun mainCoroutineContext(): CoroutineContext {
        return Dispatchers.Main.immediate
    fun mainCoroutineContext(): CoroutineContext =
        if (Flags.doNotUseImmediateCoroutineDispatcher()) {
            Dispatchers.Main
        } else {
            Dispatchers.Main.immediate
        }
}