OSDN Git Service

Quick workaround for a performance regression in IME APIs.
authorYohei Yukawa <yukawa@google.com>
Tue, 14 Jun 2016 05:16:52 +0000 (22:16 -0700)
committerYohei Yukawa <yukawa@google.com>
Tue, 14 Jun 2016 21:01:41 +0000 (21:01 +0000)
commitccb024aa2b985ddc7f65b53191a84f1891f31cf2
tree346df592527d7f56986c5adb0b231a05efa8f881
parent82f2df610894c6e423311467943a37330dbaa66b
Quick workaround for a performance regression in IME APIs.

It turns out that the performance of
InputMethodManager#getCurrentInputMethodSubtype() is regressed from ~1ms
to ~20ms when
 - Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE == -1 and
 - The active IME supports many subtypes (~100)
because we try to find a fallback subtype based on the system locales
every time when IMM#getCurrentInputMethodSubtype() is called.

This could be contributing UI janks because spell checker clients
running in the UI thread indirectly depend on that method.

Fortunatelly the critical path is in
InputMethodUtils#getImplicitlyApplicableSubtypesLockedImpl(), which is
basically a state-less method. We can easily and safely cache its
result by using LocaleList and InputMethod as cache keys.

With this CL the performance basically recovers to the Android M level.

Bug: 28889203
Change-Id: I5ed16c7f14cc18052854f4fd6c9bae8550c332ee
core/java/com/android/internal/inputmethod/InputMethodUtils.java