belaustegui
When I compile my application, I see a lot of messages like:
Compiling some/module/file.ex (it’s taking more than 10s)
I understand that this message is appearing because the compilation of those modules is slow, but I don’t know why is this and where to start looking for possible causes. Any suggestions?
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
Hello,
I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter).
The diffic...
New
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
I think I’ve found a small improvement I could contribute to <%= web_namespace %>.CoreComponents (installer/templates/phx_web/compo...
New
Other Trending Topics
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
There are three potential reasons for members of this forum to have a look at https://vutuv.de
You are tired or annoyed of LinkedIn.
Yo...
New
ICal is a library for interacting with iCalendar data. It parses iCalendars into typed Elixir structs via ICal.from_ics, and can prepare ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #ai
- #phoenix_html
- #elixirconf-us
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming











Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
NobbZ
Is your project public?
Modules are known to take long when you have a lot of macrocalls or functions with a lot of heads. Before 1.5.somewhat compile time of a function grew squared to its number of heads. I’m not sure when this was fixed (or if at all, maybe fix is master only)
belaustegui
Unfortunately no. It belongs to the company I am working for.
I don’t know if it has something to do with it, but in the 95% of those warnings, the affected module is a controller or a view.
wojtekmach
Another reason for slow compilation is if given module depends on other slow modules. [1] Is a great resource for understanding compilation. In general, you want to avoid compile-time dependencies between modules as much as possible.
On our Phoenix app, switching from
import MyApp.Router.Helperstoalias MyApp.Router.Helpers, as: Routesspeed up compilation and limited re-compilations greatly, see: [2]Elixir 1.6 will ship with improvements to
mix xrefwhich should make it easier to investigate this stuff.[1] http://milhouseonsoftware.com/2016/08/11/understanding-elixir-recompilation/
[2] Do not set compile time dependencies on the router · Issue #2530 · phoenixframework/phoenix · GitHub
[3] elixir/CHANGELOG.md at main · elixir-lang/elixir · GitHub
belaustegui
Hm, we may have something here
Running
mix xref graph --sourceon those slow modules usually shows the router as a compile time dependency, which in turn depends on lots of controllers, which depend on models, etc.I am going to try aliasing the router module instead of importing it and check the result.
Thank you @wojtekmach
a-maze-d
I know this is an old thread but I came across it, because I also got the
it's taking more than 10smessage during compilation. In my case I do know exactly the reason for that long compilation time and there is nothing really I can do about it (I did try a lot of things to eliminate it, but it wasn’t possible).Thus, I can either just accept the message or try to disable that (meaningful) warning. I didn’t find any real answer on how to disable the warning. And yes, you should first try to fix your dependencies as mentioned above, but if you might want to disable it. Hence the reason for my comment and to share what I found out
By going through the elixir code I could figure out that there is actually a compiler setting (
:long_compilation_threshold) that can disable it (or be adjusted). In yourmix.exsyou just add the following line into yourproject/0function:This removed it for me
. Don’t ask me as from which version this flag is available, thus, it might not work if you are on an old Elixir version.
If you want to see where I used it, feel free to play around with my repo, you can find it here:
BartOtten
A possible partial fix
instead of using multiple function heads
you can help the compiler by making it one function head with embedded case statement:
Routex was not able to build helper functions for 400 (generated) routes causing “too complex” issues during compilation due to the amount of generated function heads. In the upcoming version 1.2 those are rewritten to case statement variants and it now handles more than 2.000 routes.
D4no0
I would say this is a great optimisation if you are generating the code with metaprogramming.
Otherwise I would almost always recommend to take the most readable approach. There was a similar discussion on similar topics such as how
map.keyis very inefficient compared to pattern-matching.This is a implementation detail that can be changed anytime in the future and should not be a concern of the end-user that is the developer.
BartOtten
Yes. I do not expect this for manually written code. If you write 400 function heads yourself, you might be the limit yourself
Fully agree with your advice
D4no0
It can happen and I’ve worked in a codebase where we had such files that had many function heads, maintained by hand.
The thing is that, while most of those function heads were just returning constants, at some point, a new set of features introduced processing. Doing that kind of thing using
caseis much more inconvenient from readability standpoint.a-maze-d
Yes, this works for those cases where you don’t mind too much about the function signature, but in my case I do want to provide an easier/more convenient interface for the user. It’s just so much nicer to write:
Than to write the alternative (even though my library does support both):
At the end it’s the libraries decision. I didn’t want to start a discussion on what the right way is (and yes, there are many reasons to not hide issues by using this trick), but only that, if you want to get rid of the warning, you could do so with the compile flag.