Skip to content

Commit 95282a8

Browse files
authored
Improve parallelism when compiling modules (#262)
1 parent 214f15d commit 95282a8

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

lib/gettext/compiler.ex

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -378,14 +378,30 @@ defmodule Gettext.Compiler do
378378
plural_mod = Keyword.get(opts, :plural_forms, Gettext.Plural)
379379

380380
if Keyword.get(opts, :one_module_per_locale, false) do
381-
{quoted, locales} =
382-
Enum.map_reduce(known_po_files, %{}, &compile_parallel_po_file(env, &1, &2, plural_mod))
381+
known_po_files
382+
|> Enum.group_by(&Map.get(&1, :locale))
383+
|> Stream.map(fn {_locale, files} ->
384+
{quoted, locale} =
385+
Enum.map_reduce(
386+
files,
387+
%{},
388+
&compile_parallel_po_file(env, &1, &2, plural_mod)
389+
)
383390

384-
locales
385-
|> Enum.map(&Kernel.ParallelCompiler.async(fn -> create_locale_module(env, &1) end))
386-
|> Enum.each(&Task.await(&1, :infinity))
391+
{quoted, locale}
392+
end)
393+
|> Enum.map(fn {quoted, locale} ->
394+
task =
395+
Kernel.ParallelCompiler.async(fn ->
396+
create_locale_module(env, hd(Enum.to_list(locale)))
397+
end)
387398

388-
quoted
399+
{task, quoted}
400+
end)
401+
|> Enum.map(fn {task, quoted} ->
402+
Task.await(task, :infinity)
403+
quoted
404+
end)
389405
else
390406
Enum.map(known_po_files, &compile_serial_po_file(env, &1, plural_mod))
391407
end

0 commit comments

Comments
 (0)