Skip to content

Commit

Permalink
Improve parallelism when compiling modules (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
juanperi authored Jul 31, 2020
1 parent 214f15d commit 95282a8
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions lib/gettext/compiler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -378,14 +378,30 @@ defmodule Gettext.Compiler do
plural_mod = Keyword.get(opts, :plural_forms, Gettext.Plural)

if Keyword.get(opts, :one_module_per_locale, false) do
{quoted, locales} =
Enum.map_reduce(known_po_files, %{}, &compile_parallel_po_file(env, &1, &2, plural_mod))
known_po_files
|> Enum.group_by(&Map.get(&1, :locale))
|> Stream.map(fn {_locale, files} ->
{quoted, locale} =
Enum.map_reduce(
files,
%{},
&compile_parallel_po_file(env, &1, &2, plural_mod)
)

locales
|> Enum.map(&Kernel.ParallelCompiler.async(fn -> create_locale_module(env, &1) end))
|> Enum.each(&Task.await(&1, :infinity))
{quoted, locale}
end)
|> Enum.map(fn {quoted, locale} ->
task =
Kernel.ParallelCompiler.async(fn ->
create_locale_module(env, hd(Enum.to_list(locale)))
end)

quoted
{task, quoted}
end)
|> Enum.map(fn {task, quoted} ->
Task.await(task, :infinity)
quoted
end)
else
Enum.map(known_po_files, &compile_serial_po_file(env, &1, plural_mod))
end
Expand Down

0 comments on commit 95282a8

Please sign in to comment.