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

Commit 39120ff6 authored by Steve Elliott's avatar Steve Elliott
Browse files

[kairos] avoid allocs for logging strings

Flag: com.android.systemui.status_bar_mobile_icon_kairos
Bug: 383172066
Test: atest
Change-Id: Ie97777f830a81bd0cd8f2dcbf805da040078c9a6
parent b1045087
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -46,9 +46,9 @@ internal class DemuxNode<W, K, A>(
        branchNodeByKey.getOrPut(key) { BranchNode(key) }

    override fun schedule(logIndent: Int, evalScope: EvalScope) =
        logDuration(logIndent, "DemuxNode.schedule") {
        logDuration(logIndent, { "DemuxNode.schedule" }) {
            val upstreamResult =
                logDuration("upstream.getPushEvent") {
                logDuration({ "upstream.getPushEvent" }) {
                    upstreamConnection.getPushEvent(currentLogIndent, evalScope)
                }
            updateEpoch(evalScope)
@@ -147,7 +147,7 @@ internal class DemuxNode<W, K, A>(
    }

    fun getPushEvent(logIndent: Int, evalScope: EvalScope, key: K): A =
        logDuration(logIndent, "Demux.getPushEvent($key)") {
        logDuration(logIndent, { "Demux.getPushEvent($key)" }) {
            upstreamConnection.getPushEvent(currentLogIndent, evalScope).getValue(key)
        }

@@ -193,7 +193,7 @@ internal class DemuxNode<W, K, A>(
        }

        fun schedule(logIndent: Int, evalScope: EvalScope) {
            logDuration(logIndent, "DemuxBranchNode($key).schedule") {
            logDuration(logIndent, { "DemuxBranchNode($key).schedule" }) {
                if (!scheduleAll(currentLogIndent, downstreamSet, evalScope)) {
                    evalScope.scheduleDeactivation(this@BranchNode)
                }
+2 −2
Original line number Diff line number Diff line
@@ -83,7 +83,7 @@ internal class InputNode<A>(
    }

    override fun getPushEvent(logIndent: Int, evalScope: EvalScope): A =
        logDuration(logIndent, "Input.getPushEvent", false) {
        logDuration(logIndent, { "Input.getPushEvent" }, false) {
            transactionCache.getCurrentValue(evalScope)
        }
}
@@ -114,5 +114,5 @@ internal data object AlwaysNode : PushNode<Unit> {
    override fun removeDownstreamAndDeactivateIfNeeded(downstream: Schedulable) {}

    override fun getPushEvent(logIndent: Int, evalScope: EvalScope) =
        logDuration(logIndent, "Always.getPushEvent", false) { Unit }
        logDuration(logIndent, { "Always.getPushEvent" }, false) { Unit }
}
+2 −2
Original line number Diff line number Diff line
@@ -199,9 +199,9 @@ internal sealed class MuxNode<W, K, V>(val lifecycle: MuxLifecycle<W, K, V>) :
        lateinit var upstream: NodeConnection<V>

        override fun schedule(logIndent: Int, evalScope: EvalScope) {
            logDuration(logIndent, "MuxBranchNode.schedule") {
            logDuration(logIndent, { "MuxBranchNode.schedule" }) {
                if (this@MuxNode is MuxPromptNode && this@MuxNode.name != null) {
                    logLn("[${this@MuxNode}] scheduling $key")
                    logLn({ "[${this@MuxNode}] scheduling $key" })
                }
                upstreamData[key] = upstream.directUpstream
                this@MuxNode.schedule(evalScope)
+12 −13
Original line number Diff line number Diff line
@@ -43,7 +43,6 @@ internal class MuxDeferredNode<W, K, V>(
    val name: String?,
    lifecycle: MuxLifecycle<W, K, V>,
    val spec: MuxActivator<W, K, V>,
    factory: MutableMapK.Factory<W, K>,
) : MuxNode<W, K, V>(lifecycle) {

    val schedulable = Schedulable.M(this)
@@ -52,21 +51,21 @@ internal class MuxDeferredNode<W, K, V>(

    override fun visit(logIndent: Int, evalScope: EvalScope) {
        check(epoch < evalScope.epoch) { "node unexpectedly visited multiple times in transaction" }
        logDuration(logIndent, "MuxDeferred[$name].visit") {
        logDuration(logIndent, { "MuxDeferred[$name].visit" }) {
            val scheduleDownstream: Boolean
            val result: MapK<W, K, PullNode<V>>
            logDuration("copying upstream data", false) {
            logDuration(getPrefix = { "copying upstream data" }, start = false) {
                scheduleDownstream = upstreamData.isNotEmpty()
                result = upstreamData.readOnlyCopy()
                upstreamData.clear()
            }
            if (name != null) {
                logLn("[${this@MuxDeferredNode}] result = $result")
                logLn { "[${this@MuxDeferredNode}] result = $result" }
            }
            val compactDownstream = depthTracker.isDirty()
            if (scheduleDownstream || compactDownstream) {
                if (compactDownstream) {
                    logDuration("compactDownstream", false) {
                    logDuration(getPrefix = { "compactDownstream" }, start = false) {
                        depthTracker.applyChanges(
                            evalScope.scheduler,
                            downstreamSet,
@@ -75,9 +74,9 @@ internal class MuxDeferredNode<W, K, V>(
                    }
                }
                if (scheduleDownstream) {
                    logDuration("scheduleDownstream") {
                    logDuration({ "scheduleDownstream" }) {
                        if (name != null) {
                            logLn("[${this@MuxDeferredNode}] scheduling")
                            logLn { "[${this@MuxDeferredNode}] scheduling" }
                        }
                        transactionCache.put(evalScope, result)
                        if (!scheduleAll(currentLogIndent, downstreamSet, evalScope)) {
@@ -90,10 +89,10 @@ internal class MuxDeferredNode<W, K, V>(
    }

    override fun getPushEvent(logIndent: Int, evalScope: EvalScope): MuxResult<W, K, V> =
        logDuration(logIndent, "MuxDeferred.getPushEvent") {
        logDuration(logIndent, { "MuxDeferred.getPushEvent" }) {
            transactionCache.getCurrentValue(evalScope).also {
                if (name != null) {
                    logLn("[${this@MuxDeferredNode}] getPushEvent = $it")
                    logLn { "[${this@MuxDeferredNode}] getPushEvent = $it" }
                }
            }
        }
@@ -119,7 +118,7 @@ internal class MuxDeferredNode<W, K, V>(
    //    deferred to the end of this phase.
    fun performMove(logIndent: Int, evalScope: EvalScope) {
        if (name != null) {
            logLn(logIndent, "[${this@MuxDeferredNode}] performMove (patchData = $patchData)")
            logLn(logIndent) { "[${this@MuxDeferredNode}] performMove (patchData = $patchData)" }
        }

        val patch = patchData ?: return
@@ -278,7 +277,7 @@ internal class MuxDeferredNode<W, K, V>(
    }

    fun scheduleMover(logIndent: Int, evalScope: EvalScope) {
        logDuration(logIndent, "MuxDeferred.scheduleMover") {
        logDuration(logIndent, { "MuxDeferred.scheduleMover" }) {
            patchData =
                checkNotNull(patches) { "mux mover scheduled with unset patches upstream node" }
                    .getPushEvent(currentLogIndent, evalScope)
@@ -307,7 +306,7 @@ internal inline fun <A> switchDeferredImplSingle(
    return mapImpl({ switchDeferredImpl }) { map, logIndent ->
        map.asSingle().getValue(Unit).getPushEvent(logIndent, this).also {
            if (name != null) {
                logLn(logIndent, "[$name] extracting single mux: $it")
                logLn(logIndent) { "[$name] extracting single mux: $it" }
            }
        }
    }
@@ -333,7 +332,7 @@ private class MuxDeferredActivator<W, K, V>(
    ): Pair<MuxNode<W, K, V>, (() -> Unit)?>? {
        // Initialize mux node and switched-in connections.
        val muxNode =
            MuxDeferredNode(name, lifecycle, this, storeFactory).apply {
            MuxDeferredNode(name, lifecycle, this).apply {
                initializeUpstream(evalScope, getStorage, storeFactory)
                // Update depth based on all initial switched-in nodes.
                initializeDepth()
+9 −10
Original line number Diff line number Diff line
@@ -31,7 +31,6 @@ internal class MuxPromptNode<W, K, V>(
    val name: String?,
    lifecycle: MuxLifecycle<W, K, V>,
    private val spec: MuxActivator<W, K, V>,
    factory: MutableMapK.Factory<W, K>,
) : MuxNode<W, K, V>(lifecycle) {

    var patchData: Iterable<Map.Entry<K, Maybe<EventsImpl<V>>>>? = null
@@ -39,7 +38,7 @@ internal class MuxPromptNode<W, K, V>(

    override fun visit(logIndent: Int, evalScope: EvalScope) {
        check(epoch < evalScope.epoch) { "node unexpectedly visited multiple times in transaction" }
        logDuration(logIndent, "MuxPrompt.visit") {
        logDuration(logIndent, { "MuxPrompt.visit" }) {
            val patch: Iterable<Map.Entry<K, Maybe<EventsImpl<V>>>>? = patchData
            patchData = null

@@ -54,9 +53,9 @@ internal class MuxPromptNode<W, K, V>(
                        depthTracker.schedule(evalScope.compactor, this@MuxPromptNode)
                    }
                    if (name != null) {
                        logLn(
                        logLn {
                            "[${this@MuxPromptNode}] rescheduling (reschedule=$needsReschedule, depthIncrease=$depthIncreased)"
                        )
                        }
                    }
                    schedule(evalScope)
                    return
@@ -104,7 +103,7 @@ internal class MuxPromptNode<W, K, V>(
        removes.forEach { k ->
            switchedIn.remove(k)?.let { branchNode: BranchNode ->
                if (name != null) {
                    logLn("[${this@MuxPromptNode}] removing $k")
                    logLn { "[${this@MuxPromptNode}] removing $k" }
                }
                val conn: NodeConnection<V> = branchNode.upstream
                severed.add(conn)
@@ -125,7 +124,7 @@ internal class MuxPromptNode<W, K, V>(
            // remove old and sever, if present
            switchedIn.remove(k)?.let { oldBranch: BranchNode ->
                if (name != null) {
                    logLn("[${this@MuxPromptNode}] replacing $k")
                    logLn { "[${this@MuxPromptNode}] replacing $k" }
                }
                val conn: NodeConnection<V> = oldBranch.upstream
                severed.add(conn)
@@ -145,7 +144,7 @@ internal class MuxPromptNode<W, K, V>(
            newUpstream.activate(evalScope, newBranch.schedulable)?.let { (conn, needsEval) ->
                newBranch.upstream = conn
                if (name != null) {
                    logLn("[${this@MuxPromptNode}] switching in $k")
                    logLn { "[${this@MuxPromptNode}] switching in $k" }
                }
                switchedIn[k] = newBranch
                if (needsEval) {
@@ -197,7 +196,7 @@ internal class MuxPromptNode<W, K, V>(
    }

    override fun getPushEvent(logIndent: Int, evalScope: EvalScope): MuxResult<W, K, V> =
        logDuration(logIndent, "MuxPrompt.getPushEvent") {
        logDuration(logIndent, { "MuxPrompt.getPushEvent" }) {
            transactionCache.getCurrentValue(evalScope)
        }

@@ -248,7 +247,7 @@ internal class MuxPromptNode<W, K, V>(
        lateinit var upstream: NodeConnection<Iterable<Map.Entry<K, Maybe<EventsImpl<V>>>>>

        override fun schedule(logIndent: Int, evalScope: EvalScope) {
            logDuration(logIndent, "MuxPromptPatchNode.schedule") {
            logDuration(logIndent, { "MuxPromptPatchNode.schedule" }) {
                patchData = upstream.getPushEvent(currentLogIndent, evalScope)
                this@MuxPromptNode.schedule(evalScope)
            }
@@ -353,7 +352,7 @@ private class MuxPromptActivator<W, K, V>(
    ): Pair<MuxNode<W, K, V>, (() -> Unit)?>? {
        // Initialize mux node and switched-in connections.
        val movingNode =
            MuxPromptNode(name, lifecycle, this, storeFactory).apply {
            MuxPromptNode(name, lifecycle, this).apply {
                initializeUpstream(evalScope, getStorage, storeFactory)
                // Setup patches connection
                val patchNode = PatchNode()
Loading