How to speed up the start of `mix test`?

I work on a very large umbrella project. I did this config in my web app:

config :logger,
  level: String.to_atom(System.get_env("LOGGER_LEVEL") || "info"),
  handle_otp_reports: true,
  handle_sasl_reports: true
config :my_web, MyWeb.Gettext, one_module_per_locale: true, allowed_locales: ["en"]

But finally, I found that when I was testing a file, it took almost 5 seconds before my gettext app started:

These are the top logs when I run mix test filename.exs at 11:10:30:

11:10:35.496 [info]  Child Gettext.ExtractorAgent of Supervisor #PID<0.4876.0> (Supervisor.Default) started
Pid: #PID<0.4877.0>
Start Call: Gettext.ExtractorAgent.start_link([])
Restart: :permanent
Shutdown: 5000
Type: :worker

then, I removed the gettext deps, but It doesn’t solve the problem.

These are the top logs when I run mix test filename.exs at 12:37:00 after I remove the gettext deps:

2021-10-31 12:37:04.800 [info] module=application_controller function=info_started/2 line=2089  Application logger started at :nonode@nohost
2021-10-31 12:37:04.844 [info] module=supervisor function=report_progress/2 line=1546  Child :ttb_autostart of Supervisor :runtime_tools_sup started
Pid: #PID<0.4893.0>

References

You can run MIX_DEBUG=1 mix test and it will show you the timing to run tasks in recent Elixir versions. If you are on Elixir v1.11 or later and you have a Phoenix application running on latest v1.5 or v1.6, you can remove the :phoenix compiler in the :compilers option of your mix.exs. That should speed it up by 2-3s in large apps.

5 Likes

When I set MIX_DEBUG=1, Finally, I found that the time was mainly spent on loadpaths:

==> my_web
<- Ran mix deps.loadpaths in 2828ms
<- Ran mix loadpaths in 2830ms

What is your Elixir version? We have recently sped it up, make sure to try the latest v1.12.

Yes, I’ve used the latest version,

$ asdf list elixir
  1.12.3-otp-24
  ref:v1.12.3
$ asdf list erlang
  24.0.6

and I found this answer: `mix` even more slugish with Elixir 1.12.1

Maybe this problem is not easy to solve, looking forward to the arrival of Elixir 1.13 version.

The fixes in that thread are already in place. Can you please post the full output of your mix command with the debug flag here?

1 Like