marcandre

marcandre

`mix` even more slugish with Elixir 1.12.1

Playing around with time mix, there are a few things that strike me as odd

  1. It seems slow. time mix compile, a second time after nothing changed, takes about 2.4s on my machine (MacPro '09 with 6 core 3.2Ghz Xeon). Elixir 1.11.4 / OTP 23. Is that expected? We have about 300 *.ex files, 50 *.leex, and our mix.lock is 100 line long.

  2. time mix compile is 20% slower on Elixir 1.12.1 / OTP 24: about 2.9s. Is that expected?

  3. The option --no-compile saves about 20% (0.6s). Why? There is no compilation anyways in this test as I’m not modifying any file.

  4. The option --no-app-loading saves 25% (0.8s). Doc says “does not load applications (including from deps) before compiling”. Is there a short explanation as to what that entails / when not to use this?

Finally, is there a standard way to have mix feel less slugish?

Note: Not important whatsoever but time mix compilexxx takes an extra 15% (0.5s) to tell me that “The task “compilexxx” could not be found. Did you mean “compile”?” Seems like a lot of CPU cycles for that “did you mean …”!

Most Liked

josevalim

josevalim

Creator of Elixir

Sorry. I meant that you shouldn’t see a difference between mix run -e "" across Elixir versions. But I expect mix run -e "" to indeed have some additional time as it has to start all apps (and you have ~100 of them!)


I spent 15 minutes optimizing app loading and it now loads apps concurrently! :smiley: If you are willing to give it a try, you can find it in the v1.12 branch too. Since you have 6 cores, I am hoping it will at least go down to 0.2s.

So hopefully this and the upcoming phoenix change shaves ~1.1s from your times. I will keep investigating!

EDIT 1: The 15 minutes actually became 1h because it turns out the code was reaching to a central process. I was able to optimize it by adding a fast paths to apps that come from deps (which are the huge majority). In a sample project I created with 50 deps, times went from 180ms to 50ms!

EDIT 2: I got an app with 150 deps and app loading time went from 920ms to 120ms!

31
Post #4
josevalim

josevalim

Creator of Elixir

Elixir v1.12.2 is out with the improvements in this thread.

17
Post #8
josevalim

josevalim

Creator of Elixir

Hi @marcandre!

One of the biggest changes in Elixir v1.11 was the tracking of application calls. We will now warn if you call an application you don’t depend on. This means that the loading of applications, which was done after compilation, is now done before compilation. This is the process of parsing .app files and loading them into memory. This probably explains a chunk of your time, since disabling app loading saves 0.8s. If you disable it, they are loaded and started at once later on.

Some extra suggestions:

  1. Can you please measure the times for mix run -e ""? You are not supposed to see a large difference on those. Btw, what is the Elixir version you are measuring against?

  2. You can use MIX_DEBUG=1 to track the time spent on each task

  3. Phoenix master (upcoming v1.6) no longer requires the :phoenix compiler and that should save some additional time

  4. mix compilexxx takes a lot of time because we need to go through all applications, load all existing mix tasks, and see if any of them may match. This is probably another action we can parallelize.

That doesn’t mean we can’t optimize things though. Application loading, for instance, is not parallel today, and we should be able to do so somewhat trivially.

As an appreciation for your work, I would be willing to jump into this codebase, if you could share it with me, or jump into a call and explore some ideas with you. Or perhaps sharing the mix.exs + mix.lock can be enough to reproduce a lot of it (you can erase lib and run again to check). Just let me know. :slight_smile:

11
Post #2
josevalim

josevalim

Creator of Elixir

It will be on v1.12.2, probably in a week or two.

josevalim

josevalim

Creator of Elixir

Just one note on this. Some of the work in the :phoenix compiler is still necessary but it should be a bit faster. In particular, the work that is done by the :phoenix compiler is to look into view templates directories to find if new templates have been added. It is done by this function:

Maybe there is a faster way to compute this. :slight_smile:

Btw, I think I no longer need access to the repo, as my home-made 150 deps monster lock file reproduced the slow downs locally. Thanks for checking though!

Where Next?

Popular in Questions Top

aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
makeitrein
Hey all, just started picking up Elixir last week and am writing a scraper as a learning project. Baby step #1 is extracting the number ...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New

Other popular topics Top

yurko
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New

We're in Beta

About us Mission Statement