commit 7af4ff6038510c3e7faa91ac8c62a15f8aa7bf1a
parent 631da416a698df58d9253c5e77c4103ae83bd433
Author: Markus Stange <mstange.moz@gmail.com>
Date: Mon, 15 Dec 2025 23:51:22 +0000
Bug 2005806 - Add fast path for English in GetUncachedLanguageGroup to avoid ICU initialization. r=jfkthame
During startup, when geckoview.xhtml's style is initialized, we call
GetLanguageGroup("en-US") to determine font preferences. This currently
triggers expensive ICU likely subtags data loading.
Add a fast path that directly maps "en" and "en-*" to x_western without
calling AddLikelySubtags(), once we've hit the case where there's no script.
This defers ICU initialization until it's actually needed for non-English
languages, improving startup performance.
Differential Revision: https://phabricator.services.mozilla.com/D276297
Diffstat:
1 file changed, 6 insertions(+), 0 deletions(-)
diff --git a/intl/locale/nsLanguageAtomService.cpp b/intl/locale/nsLanguageAtomService.cpp
@@ -202,6 +202,12 @@ nsStaticAtom* nsLanguageAtomService::GetUncachedLanguageGroup(
if (result.isOk() && loc.Canonicalize().isOk()) {
// Fill in script subtag if not present.
if (loc.Script().Missing()) {
+ // No script. At this point it's fair to assume that en-* maps to
+ // x-western. This fast path avoids the slow call to AddLikelySubtags.
+ if (loc.Language().EqualTo("en")) {
+ return nsGkAtoms::x_western;
+ }
+
if (loc.AddLikelySubtags().isErr()) {
// Fall back to x-unicode if no match was found
return nsGkAtoms::Unicode;