Repository navigation
perf(i18n): build a language's translations on first use - #13630
yuxi-liu-wired wants to merge 2 commits into
Conversation
Every app open compiles the translation dictionaries of all 25 shipped languages, twice: `frontend.context.i18n` builds `translate` (with the English fallback) and `translate-strict` (without) with `tongue/build-translate` at namespace load. In a CPU profile of a desktop window reload, `tongue.core/build-translate` took about 400 ms of the renderer's time before the home screen, though only English and the user's language are ever read. Each locale now gets its own tongue translator, built the first time that locale is translated and kept: it is built from that locale's dict, its parent tags (`:zh-CN` -> `:zh`) and the fallback, the only dicts tongue reads for it, so every answer is the one the translator over all languages gives. In the same profile `build-translate` drops to about 20 ms. New test `lazy-translate-gives-the-full-translators-answers-test` in `src/test/frontend/context/i18n_test.cljs`: every key of every shipped language, plus parent tags (`:zh`, `:pt`), an unknown locale and a missing key, translate the same as with translators built over all languages at load, with and without the English fallback. `frontend.context.i18n-test` passes.
Every app open compiles the translation dictionaries of all 25 shipped languages three times: `frontend.context.i18n` builds `translate` (with the English fallback) and `translate-strict` (without) with `tongue/build-translate` at namespace load, and so does `electron.i18n` in the Electron main process. In CPU profiles of a desktop app open, `tongue.core/build-translate` took about 400 ms of the renderer's time before the home screen and about 280 ms of the main process's time before the window was created, though only English and the user's language are ever read. A new `frontend.lazy-translate/build-translate` is used by both instead. Each locale now gets its own tongue translator, built the first time that locale is translated and kept: it is built from that locale's dict, its parent tags (`:zh-CN` -> `:zh`) and the fallback, the only dicts tongue reads for it, so every answer is the one the translator over all languages gives. In the same profile `build-translate` drops to about 20 ms. New test `lazy-translate-gives-the-full-translators-answers-test` in `src/test/frontend/context/i18n_test.cljs`: every key of every shipped language, plus parent tags (`:zh`, `:pt`), an unknown locale and a missing key, translate the same as with translators built over all languages at load, with and without the English fallback. `frontend.context.i18n-test` passes.
|
Closing this one since dicts are loaded lazily on https://github.com/logseq/logseq/tree/devin/lui-ui-rewrite, btw, thank you for all the contributions ❤️ |
|
Measured this optimization with ablations against upstream, using the same shared warm profile, Xvfb, hyperfine, 20 measured runs per build and CPU settings fixed at 100% with turbo enabled. Whole-command mean ± standard deviation:
The three changes together reproduce the full fork's startup performance. Launch-to-real-home for the three-change build: 2.077 ± 0.017 seconds versus upstream 2.621 ± 0.025 seconds. Code-block first use was checked using real keyboard events: three backticks mount CodeMirror; typing and selection work. Ablation base: 22a29b3. Combined patch: d462a777b0. Raw benchmark JSON and per-run stages are retained locally at All three optimizations are already included in published fork-nightly commit 1771ba4. The lazy editor includes the module-registration completion fix. |
Every app open compiles the translation dictionaries of all 25 shipped languages three times:
frontend.context.i18nbuildstranslate(with the English fallback) andtranslate-strict(without) withtongue/build-translateat namespace load, and so doeselectron.i18nin the Electron main process. In CPU profiles of a desktop app open,tongue.core/build-translatetook about 400 ms of the renderer's time before the home screen and about 280 ms of the main process's time before the window was created, though only English and the user's language are ever read.A new
frontend.lazy-translate/build-translateis used by both instead. Each locale now gets its own tongue translator, built the first time that locale is translated and kept: it is built from that locale's dict, its parent tags (:zh-CN->:zh) and the fallback, the only dicts tongue reads for it, so every answer is the one the translator over all languages gives. In the same profilebuild-translatedrops to about 20 ms.New test
lazy-translate-gives-the-full-translators-answers-testinsrc/test/frontend/context/i18n_test.cljs: every key of every shipped language, plus parent tags (:zh,:pt), an unknown locale and a missing key, translate the same as with translators built over all languages at load, with and without the English fallback.frontend.context.i18n-testpasses.