Profile: https://share.firefox.dev/48FzHrj [When we call `getSelectedLocale`](https://searchfox.org/firefox-main/rev/ac7d7c131dd65058ad6b7ecfa65dc8f31a0f203e/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/components/Core.kt#576) during the initialization of the pocket stories service, we spend an unnecessary amount of time building a sorted list of the supported locales, just so that we can check whether `getCurrentLocale` returns a supported locale. I believe we could just check its language tag against the language tags in `SUPPORTED_LOCALE_ARRAY` instead. The sorting is slow because the `displayLanguage` and `displayCountry` accessors don't cache the ICU locale object, so those objects get recreated on every sort comparison.
Bug 2004793 Comment 0 Edit History
Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.
Profile: https://share.firefox.dev/48FzHrj [When we call `getSelectedLocale`](https://searchfox.org/firefox-main/rev/ac7d7c131dd65058ad6b7ecfa65dc8f31a0f203e/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/components/Core.kt#576) during the initialization of the pocket stories service, we spend an unnecessary amount of time building a sorted list of the supported locales, just so that we can check whether `getCurrentLocale` returns a supported locale. I believe we could just check `getCurrentLocale`'s language tag against the language tags in `SUPPORTED_LOCALE_ARRAY` instead. The sorting is slow because the `displayLanguage` and `displayCountry` accessors don't cache the ICU locale object, so those objects get recreated on every sort comparison.
Profile: https://share.firefox.dev/48FzHrj [When we call `getSelectedLocale`](https://searchfox.org/firefox-main/rev/ac7d7c131dd65058ad6b7ecfa65dc8f31a0f203e/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/components/Core.kt#576) during the initialization of the pocket stories service, we spend an unnecessary amount of time building a sorted list of the supported locales, just so that we can check whether `getCurrentLocale` returns a supported locale. I believe we could just check `getCurrentLocale`'s language tag against the language tags in `SUPPORTED_LOCALE_ARRAY` instead. The sorting is slow because the `displayLanguage` and `displayCountry` accessors don't cache the ICU locale object, so those internal C++ objects get recreated for every comparison performed during the sort.
Profile: https://share.firefox.dev/48FzHrj [When we call `getSelectedLocale`](https://searchfox.org/firefox-main/rev/ac7d7c131dd65058ad6b7ecfa65dc8f31a0f203e/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/components/Core.kt#576) during the initialization of the pocket stories service, we spend an unnecessary amount of time building a sorted list of the supported locales, just so that we can check whether `getCurrentLocale` returns a supported locale. I believe we could just check `getCurrentLocale`'s language tag against the language tags in `SUPPORTED_LOCALE_ARRAY` instead. The sorting is slow because the `displayLanguage` and `displayCountry` accessors don't cache the ICU locale object, so those internal C++ objects [get recreated](https://cs.android.com/android/platform/superproject/main/+/main:external/icu/android_icu4j/libcore_bridge/src/native/com_android_icu_util_LocaleNative.cpp;l=36-64;drc=61197364367c9e404c7da6900658f1b16c42d0da) for every comparison performed during the sort.