Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load modules for mix recompile in parallel #14004

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions lib/mix/lib/mix/compilers/elixir.ex
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,7 @@ defmodule Mix.Compilers.Elixir do
Map.has_key?(stale_modules, module) ->
{[module | modules_to_recompile], modules_to_mix_check}

recompile? and Code.ensure_loaded?(module) and
function_exported?(module, :__mix_recompile__?, 0) ->
recompile? ->
{modules_to_recompile, [module | modules_to_mix_check]}

true ->
Expand All @@ -385,7 +384,17 @@ defmodule Mix.Compilers.Elixir do
modules_to_recompile =
modules_to_recompile ++
for {:ok, {module, true}} <-
Task.async_stream(modules_to_mix_check, &{&1, &1.__mix_recompile__?()},
Task.async_stream(
modules_to_mix_check,
fn mod ->
# Since loading the modules themselves can be expensive,
# we want to do it inside the task too. Modules being deleted
# are uncommon, so this optimizes the common case.
{mod,
Code.ensure_loaded?(mod) and
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't that effectively synchronize on code_server?

Copy link
Member Author

@josevalim josevalim Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code loading happens mostly on the caller since Erlang/OTP 26, serializing only if there are on_load callbacks.

function_exported?(mod, :__mix_recompile__?, 0) and
mod.__mix_recompile__?()}
end,
ordered: false,
timeout: :infinity
) do
Expand Down
Loading