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