Skip to content

Commit 3cf0065

Browse files
Parallelize locale merging in mix gettext.merge (#436)
Benchmark on a 16-locale / 11-domain Phoenix app (160 PO files, ~4,700 msgids, Elixir 1.20.1 / OTP 29, Apple Silicon): mix gettext.merge priv/gettext --no-fuzzy before: 9.4s wall (55% CPU) after: 1.9-2.4s wall (341-381% CPU) ~4.9x speedup with byte-identical output files (clean git status over committed PO state after both runs). The win scales with locale count.
1 parent 7d09152 commit 3cf0065

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
* Parallelize per-locale merging in `mix gettext.merge`.
6+
37
## v1.0.2
48

59
* Only skip manifest removal on Elixir v1.19.3+

lib/mix/tasks/gettext.merge.ex

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,17 @@ defmodule Mix.Tasks.Gettext.Merge do
191191
end
192192

193193
defp merge_all_locale_dirs(pot_dir, opts, gettext_config) do
194-
for locale <- File.ls!(pot_dir), File.dir?(Path.join(pot_dir, locale)) do
195-
merge_dirs(locale_dir(pot_dir, locale), pot_dir, locale, opts, gettext_config)
196-
end
194+
pot_dir
195+
|> File.ls!()
196+
|> Enum.filter(&File.dir?(Path.join(pot_dir, &1)))
197+
|> Task.async_stream(
198+
fn locale ->
199+
merge_dirs(locale_dir(pot_dir, locale), pot_dir, locale, opts, gettext_config)
200+
end,
201+
ordered: false,
202+
timeout: :infinity
203+
)
204+
|> Stream.run()
197205
end
198206

199207
def locale_dir(pot_dir, locale) do

0 commit comments

Comments
 (0)