marcandre

marcandre OP

Compilation time for our project degraded from ~26 seconds to ~32 seconds (~23% slower) :disappointed_face:.

Did anyone else compare compilation performance on their project?

$ time mix compile --force && elixir -v
Compiling 1397 files (.ex)
Generating Enaia.Cldr for 2 locales named [:en, :und] with a default locale named :en
Generated enaia app

real	0m25.922s
user	1m59.042s
sys	0m16.722s
Erlang/OTP 27 [erts-15.2.7.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit]

Elixir 1.18.4 (compiled with Erlang/OTP 27)

time mix compile --force && elixir -v
Compiling 1397 files (.ex)
Generating Enaia.Cldr for 2 locales named [:en, :und] with a default locale named :en
Generated enaia app

real	0m32.299s
user	2m48.014s
sys	0m20.359s
Erlang/OTP 28 [erts-16.1.1] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit]

Elixir 1.19.1 (compiled with Erlang/OTP 28)

First 10 of 27 Posts Switch mode

vanderhoop

vanderhoop

The compiler is definitely doing more work overall in 1.19.X, so make sure you’re leveraging the MIX_OS_DEPS_COMPILE_PARTITION_COUNT env var, described here: elixir/CHANGELOG.md at v1.19 · elixir-lang/elixir · GitHub

If the compilation is still longer overall after setting that value to around half your cores, I’d open a bug, as I don’t think that’s expected.

vanderhoop

vanderhoop

Also, you’re the freedom_formatter guy! Thanks for the trailing commas :heart:!

josevalim

josevalim

Creator of Elixir

Can you try with the —profile time option to mix compile? I am suspecting a type system related slowdown (you can also try v1.19 branch, we just pushed more optimizations).

marcandre

marcandre OP

Thanks. Unfortunately specifying MIX_OS_DEPS_COMPILE_PARTITION_COUNT=2 didn’t noticeably change the results.

marcandre

marcandre OP

Thanks @josevalim . I’m not sure what to look for when using –profile time… There’s a lot of output :sweat_smile:. What can I do to help figure out the source of the slowdown? Do I need the output from 1.18 and what would I compare?

josevalim

josevalim

Creator of Elixir

Wait a second. Compilation took 21s but the Mix task took 33s?! Try running “mix compile —force” with MIX_DEBUG=1 and see which task is taking long.

marcandre

marcandre OP

Right. There’s a sizeable delay that doesn’t have any output, even with MIX_DEBUG=1:

MIX_DEBUG=1 time mix compile --force --profile time
-> Running mix CLI
-> Running mix loadconfig (inside Enaia.MixProject)
<- Ran mix loadconfig in 4ms
-> Running mix compile --force --profile time (inside Enaia.MixProject)
-> Running mix loadpaths --force --profile time (inside Enaia.MixProject)
-> Running mix deps.loadpaths --force --profile time (inside Enaia.MixProject)
-> Running mix archive.check --force --profile time (inside Enaia.MixProject)
<- Ran mix archive.check in 0ms
<- Ran mix deps.loadpaths in 366ms
<- Ran mix loadpaths in 367ms
-> Running mix compile.all --force --profile time (inside Enaia.MixProject)
-> Running mix compile.phoenix_live_view --force --profile time (inside Enaia.MixProject)
<- Ran mix compile.phoenix_live_view in 0ms
-> Running mix compile.erlang --force --profile time (inside Enaia.MixProject)
<- Ran mix compile.erlang in 0ms
-> Running mix compile.elixir --force --profile time (inside Enaia.MixProject)
Compiling 1397 files (.ex)
[profile] ...
[profile] Finished cycle resolution in 1ms
[profile] Finished compilation cycle of 1648 modules in 19888ms
[profile] Finished group pass check of 1648 modules in 1395ms
<- Ran mix compile.elixir in 30639ms
-> Running mix compile.app --force --profile time (inside Enaia.MixProject)
Generated enaia app
<- Ran mix compile.app in 26ms
-> Running mix compile.surface --force --profile time (inside Enaia.MixProject)
<- Ran mix compile.surface in 1604ms
-> Running mix compile.yecc --force --profile time (inside Enaia.MixProject)
<- Ran mix compile.yecc in 0ms
-> Running mix compile.leex --force --profile time (inside Enaia.MixProject)
<- Ran mix compile.leex in 0ms
<- Ran mix compile.all in 32300ms
<- Ran mix compile in 32792ms
<- Ran mix CLI in 32848ms
       33.08 real       171.14 user        20.15 sys
josevalim

josevalim

Creator of Elixir

Ok, good news is that it is not compiler related, bad news is that we don’t have instrumentation around the areas that are slow now.

When does the delay happen? Before it starts compiling each module? In the middle? At the end? My suggestion is to add some print statements around mix/compilers/elixir.ex and try to get a feeling where in the code the slowdown is.

marcandre

marcandre OP

Paying more attention to it, the mysterious delay is after the “compilation cycle” and before the “group pass check”:

[profile] Finished compilation cycle of 1648 modules in 19888ms
# At least 10 seconds passes
[profile] Finished group pass check of 1648 modules in 1395ms
<- Ran mix compile.elixir in 30639ms

Is this when the type checking is happening?

josevalim

josevalim

Creator of Elixir

No. I have a hunch this is protocol consolidation. If you open up mix/compilers/elixir.ex, you will see each_cycle and after_compile callbacks, measure those!

Where Next? Top

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 91898 914
New
AstonJ
The obligatory hello world thread! Who are you and where are you from? :stuck_out_tongue:
4616 55835 594
New
byu
@chrismccord : I just saw the Extract AGENTS.md from Phoenix.new into phx.new generator commit to the phoenix project. My initial shotgu...
New
arcanemachine
I was working on an Ecto migration and I needed a timestamp. So, for the nth time, I looked up the different data types for timestamps, a...
New
AstonJ
Just a general thread to post chat/news/info relating to AI/ML stuff that may be relevant for Nx now or in the future. Got anything to sh...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
mudasobwa
While I am working on the Language Agnostic Code Audit SaaS, which uses MetaAST (spoiler: I am expecting it to be in a good shape for ann...
New

We're in Beta

About us Mission Statement