dustinfarris

dustinfarris

Elixir is slow on my Macbook (M3 Pro/18GB)

M3 Pro with 18 GB memory

Fresh install of Elixir 1.18.1 via the install.sh script: https://elixir-lang.org/install#install-scripts

My understanding is that these times should be well under a second and they are definitely not.

[I] ~/elixir-install > hyperfine --warmup 2 -S none --export-markdown results.md -- 'elixir -e \'System.halt(0)\'' 'elixir -e \'IO.puts("Hello world")\''

Benchmark 1: elixir -e 'System.halt(0)'
  Time (mean ± σ):      2.592 s ±  1.754 s    [User: 0.163 s, System: 0.186 s]
  Range (min … max):    0.494 s …  5.542 s    10 runs

Benchmark 2: elixir -e 'IO.puts("Hello world")'
  Time (mean ± σ):      7.328 s ±  5.937 s    [User: 0.264 s, System: 0.148 s]
  Range (min … max):    2.528 s … 23.440 s    10 runs

Summary
  elixir -e 'System.halt(0)' ran
    2.83 ± 2.98 times faster than elixir -e 'IO.puts("Hello world")'

Not sure what is causing this. Need help digging in.

This seems to be exactly what I am experiencing: Elixir and Mac OS - anyone noticed a drop in performance? — but does not look like a resolution was ever found.

Most Liked

wojtekmach

wojtekmach

Hex Core Team

This is definitely unexpected. I’m getting these results:

$ elixir -e "Mix.install [:benchee] ; Benchee.run([])" 2>/dev/null | head -7
Operating System: macOS
CPU Information: Apple M2
Number of Available Cores: 8
Available memory: 24 GB
Elixir 1.18.1
Erlang 27.2
JIT enabled: true
$ which elixir ; which erl
/Users/wojtek/.elixir-install/installs/elixir/1.18.1-otp-27/bin/elixir
/Users/wojtek/.elixir-install/installs/otp/27.2/bin/erl
$ hyperfine --warmup 2 -S none -- "elixir -e 'System.halt(0)'" "elixir -e 'IO.puts(:ok)'"
Benchmark 1: elixir -e 'System.halt(0)'
  Time (mean ± σ):     127.5 ms ±   1.1 ms    [User: 127.0 ms, System: 129.1 ms]
  Range (min … max):   125.7 ms … 129.6 ms    23 runs

Benchmark 2: elixir -e 'IO.puts(:ok)'
  Time (mean ± σ):     129.0 ms ±   0.9 ms    [User: 129.0 ms, System: 133.1 ms]
  Range (min … max):   126.9 ms … 131.0 ms    23 runs

Summary
  elixir -e 'System.halt(0)' ran
    1.01 ± 0.01 times faster than elixir -e 'IO.puts(:ok)'

Could you double-check you are benchmarking with elixir/otp installed via install script? What OTP are you using?

Most of time is spent booting the VM so I’d focus on that:

$ hyperfine --warmup 2 -S none -- "erl -noshell -eval 'halt()'"
Benchmark 1: erl -noshell -eval 'halt()'
  Time (mean ± σ):      90.7 ms ±   1.2 ms    [User: 92.4 ms, System: 89.5 ms]
  Range (min … max):    88.5 ms …  92.5 ms    33 runs

Perhaps it’s the OTP builds that the installer is using, GitHub - erlef/otp_builds: Community-maintained pre-compiled Erlang/OTP for macOS. What you can try is compiling OTP using kerl and re-running the benchmark. You can compile from scratch yourself too which is easy enough:

$ git clone https://github.com/erlang/otp --branch OTP-27.2 --depth 1
$ cd otp
$ ulimit -n 1024 && ERL_TOP=$PWD MAKEFLAGS=-j8 ./otp_build setup
$ ./bin/erl -noshell -eval 'halt()'
$ hyperfine --warmup 2 -S none -- "bin/erl -noshell -eval 'halt()'"
al2o3cr

al2o3cr

The ranges seem unusually large - benchmark 2 shows almost a 10x variation between the fastest and slowest run. :thinking:

Is it possible your terminal is somehow running in Rosetta? That seems far less likely than it was in the early M1 days, but it’s the first thing I can think of that would produce that much inter-run variation (since it caches translated code).

LostKobrakai

LostKobrakai

One other random thing is what ulimits do you have set? I had to increase the laughable low default limit on my new M4 machine I set up recently.

lgp

lgp

More related to the “anyone noticed a drop in performance” link that you posted, and not really likely to be of any help, but a few years ago I noticed that elixir started up much more slowly than any of my other scripting languages. I had at one time I had a file showing the startup times of all of them but I can’t find it so I must have deleted it.

In any case, the problem went away. I can’t say that it went away because of an update to the OS or an update to elixir, and in fact I don’t remember ever knowing why it went away, but it did.

ouven

ouven

A colleague of mine, had performance issues, because the shell, he started all from, ran with Rosetta emulation. He switched from MPB with intell to one with M3 and did not do the full brew reinstall things.

Edit:
Sorry, coffee level is still low, so I did not see, that this idea already popped up

Where Next?

Popular in Questions Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
pgiesin
This should be a simple problem but I just can’t seem to figure it out. I have a standalone Elixir app that won’t find the database. Dep...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
makeitrein
Hey all, just started picking up Elixir last week and am writing a scraper as a learning project. Baby step #1 is extracting the number ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
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
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
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3268 119930 1237
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
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
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New

We're in Beta

About us Mission Statement