Repository navigation
Parse each POT file once per merge - #455
oliver-kriska wants to merge 2 commits into
Conversation
mix gettext.merge parsed every POT file once per locale. Parse the POT files once, in parallel, and pass the parsed template to the merge of each locale. The --locale and the all-locales paths now share one function, and Gettext.Merger.new_po_file/4 takes the parsed POT instead of its path. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
@oliver-kriska I've merged #453. Any work you need to do here before this becomes ready for review? |
4b5cbea to
4bb77b1
Compare
|
Rebased onto |
| pot_dir | ||
| |> Path.join("*.pot") | ||
| |> Path.wildcard() | ||
| |> Task.async_stream(&{&1, PO.parse_file!(&1)}, timeout: :infinity) |
There was a problem hiding this comment.
If locales is an empty list, we now still parse all the POT files. That's slightly inefficient but more importantly introduced a potential regression where a malformed POT file + locales == [] now raises an error (it did nothing before).
Can we keep previous behavior here? We can always fix this if we think the behavior is not correct, but I'd rather we do that in another PR.
There was a problem hiding this comment.
Good catch. Done in bd9b635: with an empty locales list no POT file is parsed, as on main. I added a test with a malformed POT file and no locale directories; it raised before this commit.
Without --locale and without locale directories nothing is merged, so the POT files are not read, as before this branch. A malformed POT file in that case does not raise. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Summary
mix gettext.merge DIRparsed every POT file once per locale. Now each POT file is parsed once and all locales reuse the parsed template.--no-fuzzygoes from 1.24 s to 0.76 s for the whole command at 8 schedulers, and its CPU time from 7.0 s to 3.2 s.mainin every run below.Changes
merge_messages_dir/3builds the list of locales ([locale]for--locale, every locale directory otherwise) and calls one function. That function parses the POT files, runs the{locale, pot}stream from #453 and warns about PO files without a POT, somerge_dirs/5and the two locale-dir helpers go away.merge_file,merge_or_create,merge_filesand the internalGettext.Merger.new_po_file/4take the parsed POT instead of its path.The POT files are parsed in parallel. With a plain
Enum.map,--localegot slower on a catalog with several large domains (0.56 s → 1.09 s on the synthetic 8 × 8 catalog below), because those parses used to run inside the parallel tasks.Most of the saving is garbage collection, not parsing. Each task used to parse a large POT while the parsed PO was already on its heap. With one scheduler, the no-change merge spends 1.78 s in GC on dirty CPU schedulers before and 0.45 s after (microstate accounting), and the number of collections drops from 11,736 to 5,551.
Measurements
Whole command, Mix startup included. Elixir 1.20.4 / OTP 29, same catalog and command in both columns (
mainmeasured at the commit of #453, before it was squashed), medians of 8 alternating runs (4 for the fuzzy row). The machine was shared with other jobs, so CPU time is the steadier number.mainwall / CPU--no-fuzzy, nothing to change--no-fuzzy, after a real extraction commit--locale,--no-fuzzy--no-fuzzy--no-fuzzy--locale,--no-fuzzyPeak memory at 8 schedulers: 335 → 280 MiB for the no-change merge and 299 → 308 MiB with fuzzy on, on the production catalog. It is higher on the synthetic catalogs (548 → 589 MiB and 303 → 363 MiB), because the parsed POT files now stay alive for the whole run.
Behavior checks
mainin every run of every row.mix test --warnings-as-errorspasses on Elixir 1.20.4 / OTP 29 and on 1.16.3 / OTP 24. The only test change is the unit test ofnew_po_file/4, which now parses the POT first.Expo.PO.SyntaxError, but now before any PO file is written and with one crash report. Before, there was one report per locale and PO files of other domains could already be rewritten. No test covers either behavior; I can add one if you want it pinned.🤖 Generated with Claude Code