Repository navigation
perf(i18n): build a locale's translator on its first use - #13788
Closed
yuxi-liu-wired wants to merge 1 commit into
Closed
yuxi-liu-wired wants to merge 1 commit into
yuxi-liu-wired wants to merge 1 commit into
Conversation
yuxi-liu-wired
force-pushed
the
perf/i18n-lazy-dicts
branch
6 times, most recently
from
October 25, 2026 11:01
b7585d8 to
8b59d8a
Compare
The two tongue translators were built at namespace load over all 25 locale dictionaries (182 ms of an app open in a renderer profile), while the app shows one locale. Each locale now gets its translator on first use, from its own dictionary, its parent tags' and English for the fallback. A test compares every key of every locale against translators built over every dictionary.
yuxi-liu-wired
force-pushed
the
perf/i18n-lazy-dicts
branch
from
October 26, 2026 11:02
8b59d8a to
1e24aba
Compare
Contributor
Author
|
Combined into #13872 with the other PRs of this theme, to keep the number of open PRs down; the commits are unchanged there. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Opening the desktop app spends about 180 ms building translations it never uses.
frontend.context.i18nbuilds two tongue translators when the namespace loads,translateandtranslate-strict, each over the dictionaries of every locale (25 of them). tongue'sbuild-translateflattens and resolves aliases in every dictionary it is given, so both translators process all 25 dictionaries, while the app shows one locale. In a renderer CPU profile of an app open (page reload to the home screen, 1010 ms in all),tongue.core/build-translatetakes 182 ms, the largest single cost of the open.The fix builds a translator per locale on its first use (memoized per locale, with or without the English fallback), from that locale's dictionary, its parent tags' (
:zh-Hantfalls back through:zh, as tongue resolves tags), and English for the fallback one.t,t-en,t-localeandtttranslate exactly as before. The first translation in a locale builds one or two dictionaries instead of 25 twice.Test:
per-locale-translators-match-one-over-every-locale-testcompares, for every key of every locale (and for a locale that has no dictionary), the result of the new translators with and without fallback against tongue translators built over every locale's dictionary, as before. It passes, and it fails when the English fallback is left out of the fallback translator.