I almost hate asking this, but it has been bothering me quite a bit. In The Little Elixir and OTP Guidebook there’s this line:
You probably won’t want to do any image processing, perform computationally intensive tasks, or build GUI applications
Why wouldn’t you?
What are the instances where using Elixir is the completely wrong tool for the job?
Elixir is not meant for all tasks, but it is a good orchestrator.
Recently I made a wrapper for imagemagick convert command, because it’s easier than writing image manipulation with Elixir
Because other languages might be better suited to be faster, and still be used by Elixir, via NIF, RUSTLER, or even create a node with another language.
But some people did
The Elixir programming model and the BEAM run-time environment have particular characteristics making them suitable for developing soft real-time, highly concurrent, fault tolerant solutions (e.g. telephony switching). To achieve those aims there are a couple of fundamental technical choices made that make the environment unsuitable for other uses:
- To make concurrency “safe” there is no in-place updating of variables
- To support concurrency, predictable latency and fault tolerance, code execution is scheduled and monitored by the VM - this oversight of code execution is costly
Implications in terms of the examples mentioned above are:
Image Processing: Typical image processing algorithms (e.g. convolution filters) involve incrementally reading from a source image structure and writing to a destination memory structure pixel by pixel (see the pseudo-code 2/3 of the way through this article https://en.wikipedia.org/wiki/Kernel_(image_processing) ). This can only be efficient if the destination structure is pre-allocated and incrementally updated. Elixir and Erlang don’t allow this - a new structure has to be generated each time you want to update a single pixel.
Computationally intensive: The cost of overseeing executing code results in significantly slower execution. In addition, computationally intensive algorithms often have hand crafted memory manipulation in order to optimise performance - again, a no-no in Elixir / Erlang
Building GUI applications: This refers to desktop UIs - basically there is limited tooling to make nice native applications. The platform was designed for server operations and that is what it excels at. You can take a look at what’s possible by typing :wx.demo into iEx - not bad, but not quite as slick as the latest .Net widget toolkits.
For UI, You can also try Scenic.
Thank you - great answer. This gave me a better understanding of Elixir as a whole. For #2: what are some examples of computationally intensive use cases? I still think it’s good for that.
The reason I ask is because I’m trying to find an excuse to use it at work, but not if it’s absolutely not the right tool for the job.
Computationally intensive would be something like seismic data processing, inversion of potential field geophysics, fluid dynamics modelling, modelling stresses in engineering, weather system modelling, training AI systems, CGI rendering (typically handled by specialised GPU-based systems), cryptography (particularly trying to break it) - processes that can run for hours, days or even weeks.
Adding up numbers in a financial system probably doesn’t count as computationally intensive
Understood. I’m a beginner so excuse the dumb question. In my mind, I would assume one would want the lang that can handle the most computationally intensive tasks? What lang would that be?
So Elixir is mostly if you want safety as in fault-tolerance etc?
For computationally intensive, Fortran, C, C++ and now Rust would be typical.
Elixir has a few characteristics that are important for certain types of system:
- Fault tolerant (=> good for servers of many kinds, particularly if you don’t like getting out of bed at 3am to reset them)
- Very good concurrent programming model and run-time environment (=> good for systems where you have lots of users or activities going on that need to interact with each other - e.g. multi-user games, chat systems, GPS tracking of trucks/packages whatever)
- Highly productive for web development (=> good for startups who don’t want to pay for a big team of web developers to get something solid out the door in a sensible timeframe)
There’s a good thread on who is using Elixir (& Phoenix) and for what: Are you using Phoenix in production for public facing traffic? Let's hear your story! If you want to get interviewed (email based or a podcast) come on in
Elixir for Web
Golang for Service (Service API)