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

Commit ab77bd97 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Don't call 'getShortDescription' when tracing is not enabled

The call to 'getShortDescription' is expensive. Currently, it's called
even if tracing is not enabled, which slows down input processing. Move
this into an 'if' statement, which will ensure that it's only called if
tracing is enabled.

If we find that this is still too expensive (slows down input processing
too much when tracing is enabled), we should consider getting rid of
this trace completely.

Bug: 395115521
Flag: EXEMPT bugfix
Test: none
Change-Id: Icbf2ea32e6ebc4c944d214c953b11a5d7a7cdede
parent 1d883bc1
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -290,9 +290,15 @@ public abstract class InputEventReceiver {
    @SuppressWarnings("unused")
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    private void dispatchInputEvent(int seq, InputEvent event) {
        Trace.traceBegin(Trace.TRACE_TAG_INPUT, "dispatchInputEvent " + getShortDescription(event));
        if (Trace.isTagEnabled(Trace.TRACE_TAG_INPUT)) {
            // This 'if' block is an optimization - without it, 'getShortDescription' will be
            // called unconditionally, which is expensive.
            Trace.traceBegin(Trace.TRACE_TAG_INPUT,
                    "dispatchInputEvent " + getShortDescription(event));
        }
        mSeqMap.put(event.getSequenceNumber(), seq);
        onInputEvent(event);
        // If tracing is not enabled, `traceEnd` is a no-op (so we don't need to guard it with 'if')
        Trace.traceEnd(Trace.TRACE_TAG_INPUT);
    }