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

Commit 7c5f73d3 authored by Steve Elliott's avatar Steve Elliott
Browse files

[kairos] remove redundant NetworkScope.schedule(MuxNode)

addresses a long-standing TODO

Flag: EXEMPT unused
Test: atest kairos-tests
Change-Id: I0a85151515fb94b0e589b63fe555f9d993b59116
parent 60f5dd1b
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -66,8 +66,6 @@ internal interface NetworkScope : InitScope {

    fun schedule(state: TStateSource<*>)

    suspend fun schedule(node: MuxNode<*, *, *>)

    fun scheduleDeactivation(node: PushNode<*>)

    fun scheduleDeactivation(output: Output<*>)
+9 −1
Original line number Diff line number Diff line
@@ -188,6 +188,14 @@ internal sealed class MuxNode<K : Any, V, Output>(val lifecycle: MuxLifecycle<Ou
    }

    abstract fun hasCurrentValueLocked(transactionStore: TransactionStore): Boolean

    fun schedule(evalScope: EvalScope) {
        // TODO: Potential optimization
        //  Detect if this node is guaranteed to have a single upstream within this transaction,
        //  then bypass scheduling it. Instead immediately schedule its downstream and treat this
        //  MuxNode as a Pull (effectively making it a mapCheap).
        depthTracker.schedule(evalScope.scheduler, this)
    }
}

/** An input branch of a mux node, associated with a key. */
@@ -202,7 +210,7 @@ internal class MuxBranchNode<K : Any, V>(private val muxNode: MuxNode<K, V, *>,
        val upstreamResult = upstream.getPushEvent(evalScope)
        if (upstreamResult is Just) {
            muxNode.upstreamData[key] = upstreamResult.value
            evalScope.schedule(muxNode)
            muxNode.schedule(evalScope)
        }
    }

+1 −1
Original line number Diff line number Diff line
@@ -409,7 +409,7 @@ internal fun <K : Any, A> switchDeferredImpl(
                // Schedule for evaluation if any switched-in nodes have already emitted within
                // this transaction.
                if (muxNode.upstreamData.isNotEmpty()) {
                    evalScope.schedule(muxNode)
                    muxNode.schedule(evalScope)
                }
                return muxNode.takeUnless { muxNode.switchedIn.isEmpty() && !isIndirect }
            }
+3 −3
Original line number Diff line number Diff line
@@ -75,7 +75,7 @@ internal class MuxPromptMovingNode<K : Any, V>(
            if (depthTracker.dirty_depthIncreased()) {
                depthTracker.schedule(evalScope.compactor, node = this)
            }
            evalScope.schedule(this)
            schedule(evalScope)
        } else {
            val compactDownstream = depthTracker.isDirty()
            if (evalResult != null || compactDownstream) {
@@ -291,7 +291,7 @@ internal class MuxPromptPatchNode<K : Any, V>(private val muxNode: MuxPromptMovi
        val upstreamResult = upstream.getPushEvent(evalScope)
        if (upstreamResult is Just) {
            muxNode.patchData = upstreamResult.value
            evalScope.schedule(muxNode)
            muxNode.schedule(evalScope)
        }
    }

@@ -451,7 +451,7 @@ internal fun <K : Any, A> switchPromptImpl(
                    // Schedule for evaluation if any switched-in nodes or the patches node have
                    // already emitted within this transaction.
                    if (movingNode.patchData != null || movingNode.upstreamData.isNotEmpty()) {
                        evalScope.schedule(movingNode)
                        movingNode.schedule(evalScope)
                    }

                    return movingNode.takeUnless { it.patches == null && it.switchedIn.isEmpty() }
+0 −5
Original line number Diff line number Diff line
@@ -81,11 +81,6 @@ internal class Network(val coroutineScope: CoroutineScope) : NetworkScope {
        stateWrites.add(state)
    }

    // TODO: weird that we have this *and* scheduler exposed
    override suspend fun schedule(node: MuxNode<*, *, *>) {
        scheduler.schedule(node.depthTracker.dirty_directDepth, node)
    }

    override fun scheduleDeactivation(node: PushNode<*>) {
        deactivations.add(node)
    }