markdev
Is there any significant difference in the runtime speed of programs written in erlang vs. elixir? What (if any) advantages are there to writing one’s source code in raw erlang instead of elixir?
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app?
Looking for hints regarding:
Addi...
New
Kia ora,
We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
Hi all, I wanted to ask how the community is dealing with post-release steps.
Today we have Ecto migrations, which make sure that the db...
New
Hello,
I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
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
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
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
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #ai
- #genstage
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex











Showing Posts 1 to 10- Show Best Posts
- Show All Posts (oldest first)
- Show All Posts (newest first)
benwilson512
There are no differences, both compile to the same byte code. Erlang is not more “raw” or low level than Elixir.
idi527
Enumfunctions are slower than their counterparts in erlang since they do more work (protocol dispatch).@compile {:inline, ...}) require additional function call, which increases reduction count and can affect execution time of that function.josevalim
Yes! Elixir is slightly slower because we dispatch to Enum.reduce and Erlang doesn’t perform a remote call.
We inline most common types with the list type coming first. So for the builtin types, that should be no difference in performance.
@compile {:inline, ...}only works within the same module so it is not a general mechanism for wrapping Erlang functions. The Elixir compiler, however, does inline most of its calls to:erlang.So there are tiny differences in some very specific cases, but they are quite unlikely to matter in general.
idi527
Also elixir code might be sometimes less efficient because of the way people write it and not due to the language itself.
.several times instead of a single pattern matchKeyword.fetchon every element in an “opts” list instead of iterating over it oncemichalmuskala
In general the differences are tiny. Those should also decrease in the next OTP release with several patches to the compiler optimising some idioms common in Elixir.
There are also some cases, where the way Elixir programs are usually structured might be more efficient than Erlang programs.
.instead ofmaps:getcallsAnd there are probably more - it’s not black and white. Overall I wouldn’t expect major performance differences between Erlang and Elixir code, especially if you’re writing it paying attention to performance.
OvermindDL1
I made a fixed version a half-year ago! ^.^
Mine is actually faster than even erlang’s in some cases (same speed in the average case) due to my design requiring you to essentially ‘type’ the arguments so it can generate the most efficient code. It was mostly a proof of concept though (hence why it’s in my ‘proof-of-concept’ repo) and never finished it up to put it out into it’s own package.
But the syntax (as from this benchmark ex_core/bench/comprehension_bench.exs at master · OvermindDL1/ex_core · GitHub ):
I’m actually surprised at that it inlines at the compiler step instead of just making those calls
defmacrodelegations or so… Seems a duplication of effort? (Though I’m betting the compiler-level inlining was added well before macros were. ^.^)Even the Elixir standard
to_string/1can take an iolist and put out a binary just fine so there is no reason to. In some cases binary appending is more efficient however.This speed difference should be reduced in OTP 21 I think it was, though there will still be a difference, just not ‘as’ big.
It would be interesting Elixir didn’t use
.for maps and instead had a built-in lens/prism functionality that ended up generating matchers.Yeah the default access pattern of
opts[:blah]is definitely not the most efficient by far… (and yet I do it a lot due to its simplicity) ^.^;Back in my ol’ Erlang days I had a fairly simple library, similar to the commandline-opt-parse module in Erlang that did a single pass over the output and spit back out a tuple (based on the requested values) after fixing them up (erlang style proplists are so much nicer than elixir style keyword lists) into a normalized output based on what I wanted, or else either log an error or perhaps throw an error, etc… I really should rewrite it to handle Elixir’s more limited KWLists sometime, smaller implementation for sure.
+++
Doesn’t
.delegate tomaps:getor is it going to some internal implementation to match out (which shouldn’t that then be the same speed asmaps:getunless it were inlined into the module?)?Ooo is the new OTP version going to make iterating over binaries faster than lists? Lists have always been so much faster than binaries for so many things ever since I started erlang (though significantly larger).
This this this is a big thing. Erlang had it’s share of macro-like things but they are a bit of hell to write, especially compared to Elixir macro’s.
+1 They still generate the same code to the same VM. ^.^
CptnKirk
Tell me more. I’m new to Elixir and all of the learning materials I’m using focus on structs. Didn’t realize Records were a thing until today. What are the pros/cons and why is there a performance benefit to Records over Structs/Maps?
idi527
See
I think they are implemented slightly differently in elixir, though.
But structs are generally much nicer to work with because they are maps and not tuples. For example, IIRC cowboy 2.0 moved from using records to represent its
Reqobject to maps. But from reading its (as well as ranch and cowlib) source code I got a feeling that cowboy was striving for completeness and ease of use rather than performance.michalmuskala
foo.barexpands to:I was mostly writing about memory size, which has some less direct effect on the applications triggering less GC, sending binaries between processes without copying, allowing for more structural sharing with sub binaries, etc. The difference is actually not that big on OTP 20 already when iterating over bytes (I think there are some things that should make binaries even faster on OTP 21).
Benchmark code: string_bench.exs · GitHub
CptnKirk
The Google Groups thread seems to imply that structs/maps will be more performant when doing the typical pattern match and have benefits wrt polymorphism and protocol support. It seems the only thing Records excel at are access within tight loops.
If I understand this correctly, it seems that Structs would outperform Records for the vast majority of general state holding problems. Like the state of a Cowboy
Reqobject and nearly every GenServer.Am I misreading this?