Repository navigation
Conversation
Split the Gettext backend by locale so each locale compiles as a separate module in parallel. All translations previously compiled into one module, which dominated package compilation and delayed dependent applications. Retain the backend API and translation lookups. Applications can restore a single module by configuring split_module_by for Timex.Gettext.
|
It may be worth checking out Gettext main. It has several optimizations there which may alleviate the need for this. |
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.
Summary of changes
Timex.Gettextcompiles all 280 PO files (35 locales × 8 domains) into one module. Elixir compiles a module in a single process, solib/l10n/gettext.extakes nearly all of the time timex takes to compile, and the other files finish long before it. In a profiled build, it was 5.6 s of the package's 5.7 s. When Mix compiles an application's dependencies, every package that depends on timex waits for it too.This PR passes
split_module_by: [:locale]touse Gettext.Backend. Gettext then generates one internal module per locale (Timex.Gettext.T_de, ...) and compiles them in parallel.Timex.Gettextkeeps the same functions, and each of its clauses calls into the module for that locale.useoptions, so an application can still go back to a single module withconfig :timex, Timex.Gettext, split_module_by: [].Results
mix deps.compile timex --forcein a project that depends on timex by path, with one partition, median of 5 rounds after a warm-up, with the variants interleaved, on a 24-core Intel Core Ultra 9 285HX, Linux, Elixir 1.20.5, OTP 29.1.2, Gettext 1.0.2:mainTimex.Gettext*modulesI also tried
split_module_by: [:locale, :domain], which gives 281 modules (1.8 MB): 1.48 s (1.43–1.52) and 14.5 s of CPU time. It was slower than splitting by locale in all rounds, so this PR splits by locale only.Verifying change
Run from a project that depends on timex, once on each build, then compare the two files:
Checklist
@moduledoc false)AI disclosure
I used Claude Code (Claude Opus 5.5) to find the slow module, write the change and run the measurements. I reviewed and validated the code and the results myself.