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

Commit 17323794 authored by Shai Barack's avatar Shai Barack
Browse files

Optimize Message comparison to be branchless.

Refactor `Message.compareMessages` to use a branchless formula based on `Long.signum` for `when` and `insertSeq` differences, maintaining the same comparison order.

This is based on a pprof of MessageQueuePerfTest which shows that most branch misses in our benchmarks come from Message#compareMessages.

https://pprof.corp.google.com/?id=1c73d480facfd5c483a5e72a5450e67d&metric=branch-misses&flamesearch=android.os.Message.compareMessages

This refactor produces smaller code:
https://godbolt.org/z/bvGh7aadG

And faster:
https://godbolt.org/z/Kf1v9qcYe

Flag: EXEMPT PURE_REFACTOR
Bug: 421623328
Change-Id: I4fb81774c00276747cca84ce070a4511a88501c5
parent 80166f36
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment