Slow compiling large project

I’m having troubles working on my Phoenix project.
When I hit the save button, it shows (Compiling 87 files (.ex)) and the bigger the project gets the slower it becomes.
I have a feeling its due to references in my project, I use Ecto schemes all over the place.

When i hit save in my editor it starts a massive compile and it is taking up to 10 sec for now … it’s driving me nuts :wink: :face_with_thermometer:

I already fiddled with mix xref

2 Likes

My project is roughly the same size/shape as yours and I’m experiencing similar compile times. It hasn’t really gotten to me yet… but one day it will :slight_smile:

I’m also super curious if this can be improved.

The Elixir compiler is good at determining module dependencies and so only compiles what it needs to. The xref you showed suggests you modified something high in your module dependency tree (web/models/checklist_row.ex ??) which would force a recompile of all modules that depend on that. Which understandably is a lot of your application.

Also changing your config.exs and friends will also force a recompile of most the app.

the problem is, almost every file i change it triggers a chain of compilations.
not only if i change checklist_row.ex

what i see in checklist_row.ex it has many_to_many :projects, join_trough: …
and project.ex has (many) many_to_many join_trough to different schemes.
maybe that is triggering the chain of compilations.

Have a look at this post, it might shed some light on your problem:
http://milhouseonsoftware.com/2016/08/11/understanding-elixir-recompilation/

From what I could glance quickly, the main problem is that the models have circular relationships, mainly the project.ex. When there are cycles, once something in the cycle changes, every other file which is part of the cycle will also be recompiled.

Also, make sure you have ecto up to date.

4 Likes

Wonderful resources here, thanks! I’ll try to apply some of the suggestions and see what shakes out.

Thanks, i will dive in :slight_smile: Sound’s like the problem i have …

The problem i had with recompiliing when changing 1 code, i called a function from the YourApp.ex in the layout.view. So i removed the function call from YourApp.ex, my compilation only run that on that particular file, instead of whole 100+ files.

1 Like