jeffdeville

jeffdeville

How to determine why elixir compilation w/ a macro is taking 202seconds

I’ve got a macro that wasn’t impacting my project compilation speed much. I added a small feature to it, and now it’s ~50x slower. But at least to look at it, it certainly doesn’t appear as if 50x more work is being done.

Are there any tools I can use to determine why this is the case? After the AST is generated (this part is fast), I’m not sure where things ‘go’, or what tools I might have to identify the source of my slowdown.

Marked As Solved

jeffdeville

jeffdeville

Thanks Jose. I fixed the problem and I think I’ve got something interesting to report.

First, I made the changes you suggested. Boiled each method down to 1 line in another module. The compilation time was still 108 seconds.

The fix was to inspect all of the values I was writing into my @docs that were not strings. (atoms, and ints)

I changed my @docs from:

@doc """
#{unquote(desc)}
* Field Type: #{unquote(type)}
* Units: #{unquote(units)}
* Addr: #{unquote(addr)}
* Num Bytes: #{unquote(num_bytes)}
"""

to

@doc """
#{unquote(desc)}
* Field Type: #{unquote(inspect type)}
* Units: #{unquote(inspect units)}
* Addr: #{unquote(inspect addr)}
* Num Bytes: #{unquote(inspect num_bytes)}
"""

and my compilation times sped up 43x

Also Liked

josevalim

josevalim

Creator of Elixir

If this is being called a lot of times, then yes, the amount of code you generate will have a direct impact on compilation times. If you can post a snippet, we can help reduce the compilation time, but this may very well be a hint to find another approach that generating many many functions.

In any case, it is also worth mentioning that Elixir v1.5 speeds up how function definitions for large modules, so maybe try out Elixir master and see if that improves the situation.

josevalim

josevalim

Creator of Elixir

That’s very interesting. Thanks for reporting back. Which Erlang version were you using?

Can you also post what those strings would look like before and after your changes? I am wondering if inspecting is limiting something that would otherwise be very large or if it is forcing the string to be rendered as a binary which would affect the rest of compilation.

Compilation of large literal binaries/strings have been generally improved in OTP 20 though: Move expansion of strings in binaries to v3_core by josevalim · Pull Request #1131 · erlang/otp · GitHub

Where Next?

Popular in Questions Top

LegitStack
I’m hoping you guys can give me some general advice and perhaps code examples if you’re feeling up to it. I’m very interested in Elixir,...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
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
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
Kagamiiiii
Student & New to elixir. Nice language. I want to convert a english character, e.g. “a”, which is stored in a variable, to it’s asci...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
Fl4m3Ph03n1x
Background Let’s assume I have a typical GenServer that receives messages as requests, does some operation in a DB and returns responses....
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
idi527
I’ve been re-reading swift book again and noticed that multiline strings there don’t have a trailing line break, unlike in elixir iex(2)...
New

Other popular topics Top

albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
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
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
magnetic
Hey :wave:t3: Elixir community, I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New

We're in Beta

About us Mission Statement