Skip to content

perf(i18n): build a language's translations on first use - #13630

Closed
yuxi-liu-wired wants to merge 2 commits into
logseq:masterfrom
yuxi-liu-wired:perf/open-i18n
Closed

yuxi-liu-wired wants to merge 2 commits into
logseq:masterfrom
yuxi-liu-wired:perf/open-i18n

Conversation

@yuxi-liu-wired

@yuxi-liu-wired yuxi-liu-wired commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

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.

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.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 6, 2026
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.
@tiensonqin

Copy link
Copy Markdown
Contributor

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 ❤️

@tiensonqin tiensonqin closed this Oct 7, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 8, 2026
@yuxi-liu-wired

Copy link
Copy Markdown
Contributor Author

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:

  • Upstream baseline: 2.819 ± 0.025 seconds.
  • Lazy translation compilation alone: 2.538 ± 0.026 seconds.
  • Lazy code editor alone: 2.664 ± 0.035 seconds.
  • Lazy MCP/updater dependencies alone: 2.717 ± 0.034 seconds.
  • Translation + code editor: 2.391 ± 0.032 seconds.
  • All three: 2.277 ± 0.017 seconds.
  • Our complete nightly: 2.285 ± 0.031 seconds.

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 results/startup/20261008-190710, with individual-change comparisons at 20261008-185448, 20261008-185654, and 20261008-185902.

All three optimizations are already included in published fork-nightly commit 1771ba4. The lazy editor includes the module-registration completion fix.

yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 11, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 13, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 16, 2026
@yuxi-liu-wired
yuxi-liu-wired deleted the perf/open-i18n branch October 21, 2026 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants