Skip to content

STOP GENERATING THOUSANDS OF MODULES!!! #10755

Open
@edescourtis

Description

@edescourtis

I know the use of meta-programming is fun. But the BEAM doesn't handle loading thousands of modules very well. We have several Google libraries in our deployment Elixir and just loading Google API libraries takes over a minute!!! OVER A MINUTE for a few APIs!!!!

iex -S mix run --no-start
fn ->
  times =
    Application.loaded_applications()
    |> Enum.map(fn {app, _desc, _vsn} ->
      modules = Application.spec(app, :modules)
      {time, _result} = :timer.tc(fn -> Enum.each(modules, &Code.ensure_loaded!/1) end)
      {app, System.convert_time_unit(time, :microsecond, :millisecond)}
    end)
    |> Enum.sort_by(&elem(&1, 1), :asc)

  Enum.each(times, &IO.inspect/1)
  times |> Enum.map(&elem(&1, 1)) |> Enum.sum() |> IO.inspect()
end.()
# {application, time_in_ms}
...
{:google_api_you_tube, 6336}
{:google_api_dfa_reporting, 11710}
{:google_api_vision, 15091}
{:google_api_content, 29394}

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions