Sebb

Sebb

Is &foo/1 really faster than &foo(&1)

Exercism states, that I should rather capture a function instead of creating a new one.
While this makes sense, it seems to me that this should be an easy task for the compiler to optimize.

In particular I prefer for example &(&1+&2) over &+/2.

Marked As Solved

josevalim

josevalim

Creator of Elixir

It is not faster. Those are equivalent. :slight_smile:

10
Post #1

Also Liked

LostKobrakai

LostKobrakai

There’s however a difference between &Module.fun/2 vs. any other form. The fully quantified version (mod, fun and arity) can be optimized to not use an anonymous function, which makes it more performant. This is important in situations like :telementry handlers, which might be called very often, as described in the docs:

hauleth

hauleth

To clarify - difference is meaningful only when that capture crosses process boundary. Within single process it will be unnoticeable or even may be slightly slower when you call local capture within single module.

LostKobrakai

LostKobrakai

To the contrary. One of the big features of telemetry is that handlers are executed in the process emiting any event, which means there’s no message passing involved in providing data to said handlers – and handlers can then decide how to handle the provided data. That however means the handler is passed around between processes.

Last Post!

dimitarvp

dimitarvp

Interesting. Any good starting pointers on code to read? Same repo as you sent a link to earlier, surely, but probably also concrete implementations e.g. Prometheus, Zipkin, Jaeger etc. adapters?

/CC @hauleth

Where Next?

Popular in Questions Top

vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

Other popular topics Top

joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31586 112
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 49266 226
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

We're in Beta

About us Mission Statement