Very long compile times for small changes

Hi there,

I am currently working on a Forum/community system in Elixir using Phoenix. First everything was nice, but slowly the compile times increased. It got so bad that now small changes can take up to 30 seconds.

I already read about compile dependencies and stuff, but I can’t really make sense of tools like mix xref. The generated graphic is unusable (image viewers seem not to be able to show the image) and the tree/stats views are confusing to me.

I already tried to fight this problem by stripping out imports and requires, and it made things better – but by far not good.

Can somebody point me to resources explaining how to use tools like mix xref or explain me what I am doing wrong?

My project is a FLOSS and hosted on Github: https://github.com/ckruse/cforum_ex/

Edit: also please don’t mince matters. If you think I am using anti patterns and thus causing this problem myself, tell me. I can handle that and love to learn.

Thanks in advance,
CK

1 Like

Did you try deleting the _build folder? Whenever I have the slightest problem I always first delete _build, deps and .elixir_ls

Yes, did that. Doesn’t change anything.

I get this while trying to run build it:

➜  cforum_ex git:(master) mix deps.get
** (Code.LoadError) could not load /Users/kwando/projects/cforum_ex/config/appsignal.exs
    (elixir) lib/code.ex:1192: Code.find_file/2
    (elixir) lib/code.ex:758: Code.eval_file/2
    (mix) lib/mix/config.ex:158: anonymous fn/2 in Mix.Config.__import__!/2
    (elixir) lib/enum.ex:1948: Enum."-reduce/3-lists^foldl/2-0-"/3
    (mix) lib/mix/config.ex:157: Mix.Config.__import__!/2
    (stdlib) erl_eval.erl:680: :erl_eval.do_apply/6
    (elixir) lib/code.ex:240: Code.eval_string/3

Just run touch config/appsignal.exs

Ah, right - you have to create a appsignal.exs, this file contains secrets and thus is not in the repo. A simple use Mix.Config in this file should be enough.

I’ve cloned your app and it seems to compile at the same speed as my own projects

https://asciinema.org/a/2N1DeYHwWBbrXbJxlM9hJRTca

And now change e.g. lib/cforum_web/layout/app.html.eex and watch getting a whole bunch of files recompiled :slight_smile:

Elixir files or assets? I can’t seem to run the migrations and therefor not the app so I can’t really check.

No, assets are in the webpack domain. Elixir files (.ex or .eex).

You can check w/o running the migrations by using mix compile without calling mix clean before.

➜  cforum_ex git:(master) ✗ mix ecto.create
The database for Cforum.Repo has already been created
➜  cforum_ex git:(master) ✗ mix ecto.migrate

21:31:50.913 [info]  == Running 20181023062557 Cforum.Repo.Migrations.MakeTagsGlobal.change/0 forward

21:31:50.915 [info]  alter table tags
** (Postgrex.Error) ERROR 42P01 (undefined_table) relation "tags" does not exist

EDIT: didn’t read the previous message correctly, will check now with mix compile

this is a project with some legacy; if you want to try it out, run mix ecto.load (this loads the database structure from version 4) and then mix migrate.cf4 (this migrates to the v5 structure) – sorry, still a lot of details to work on :slight_smile:

I am going offline right now (it’s pretty late here), thanks for your patience and your work! Will check again tomorrow morning.

@cjk did you get anywhere with this?

I’ve done a bit of research but also so far not able to make sense of the resources/discussions that I’ve found.

I’m sure it’s my bad code organisation that is causing this (lot’s of aliases and shared code).

I am just not too sure how to tackle this and find out some quick wins.

For me the slow compile is probably due to my laptop, but the trigger of recompiling 74 files after changing the slightest thing is the problem.

Sadly no. I am still not able to make sense of any of this. I’m also pretty confused on how to organize the code to avoid these dependencies…

Phoenix v1.4 comes with improvements in this area. Do these steps:

  1. https://gist.github.com/chrismccord/bb1f8b136f5a9e4abc0bfc07b832257e#add-a-routes-alias-and-update-your-router-calls
  2. Add config :phoenix, :plug_init_mode, :runtime to your config/dev.exs
3 Likes

Thanks, Jose, for your reply. Sadly this doesn’t change anything. A change on layout/app.html.eex still recompiles 106 files. Same for other files. Compile times are really high in this project, and I can’t wrap my head around this :frowning: sorry.

Check out mix xref graph --label compile --sink layout/app.html.eex (I hope that this will work with EEx files).

1 Like

No, it doesn’t. But it works on layout_view.ex – but I don’t understand the results.

➜ ckruse@Pug ~/Code/selfhtml/cforum_elixir (master) ✗ % mix xref graph --label compile --sink lib/cforum_web/views/layout_view.ex
lib/cforum_web/mailers/notification_mailer.ex
└── lib/cforum_web/views/layout_view.ex (compile)
lib/cforum_web/mailers/user_mailer.ex
└── lib/cforum_web/views/layout_view.ex (compile)
➜ ckruse@Pug ~/Code/selfhtml/cforum_elixir (master) ✗ % touch lib/cforum_web/views/layout_view.ex
➜ ckruse@Pug ~/Code/selfhtml/cforum_elixir (master) ✗ % mix compile
Compiling 106 files (.ex)

When only two files compile-time depend on layout_view.ex, why does a change cause 106 files to be recompiled?

2 Likes

I am also struggling from this high compile time. But now a kind of adjusted to this. Tried to reduce the compile time many ways, but nothing came out good.