Skip to content

Simplify all_loaded call #326

@josevalim

Description

@josevalim

Today it is defined as:

  defp all_loaded do
    timed_log "all loaded", 1 do
      Applications.get_modules_from_applications()
      |> Enum.filter(fn module ->
        try do
          Code.ensure_loaded?(module) and function_exported?(module, :module_info, 0)
        rescue
          _ ->
            false
        end
      end)
    end
  end

Unfortunately, Code.ensure_loaded? is a bit expensive. Luckily, Application.spec(:app_name, :modules) should return correct and up to date information, except for the current app and path dependencies, since "live code compilation" (as done by Phoenix and others) may define new modules and without reload the application spec (which would require the app to stop).

So my suggestion is to improve Applications.get_modules_from_applications() to Application.spec(:app_name, :modules) for all apps, except the current apps and path deps (which you can compute on boot). For those, you do a File.ls(path_to_ebin) and get the beam files. This should actually fix bugs, given if you define a module in a Phoenix app today, it likely won't be picked by Applications.get_modules_from_applications()?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions