Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elixir is harder than you think #215

Open
ndrean opened this issue Jul 15, 2024 · 4 comments
Open

Elixir is harder than you think #215

ndrean opened this issue Jul 15, 2024 · 4 comments

Comments

@ndrean
Copy link
Contributor

ndrean commented Jul 15, 2024

An open discussion: Elixir maybe harder than you think to get it speedy. It is VERY easy to write "inefficient" code.

Some examples:

  • this video is a good example on how to write beautiful but inefficient Elixir code.
    The todo:
    Screenshot 2024-07-15 at 15 41 57

The first "poor" first "natural" version:
Screenshot 2024-07-15 at 15 39 52

  • a very instructive video. A comparison of using tuples vs lists vs maps. In particular, :erlang_disasm.file and the add-on beamdasm if you are very curious.

Screenshot 2024-07-15 at 15 36 04

  • Another video. The repo with the Go and Elixir 1 & 2 versions.
    The todo: repeatedly pick a random element from a large list of words

He "solved" the issue of constant time access by using the AJA library
Screenshot 2024-07-15 at 17 52 28

@ndrean
Copy link
Contributor Author

ndrean commented Jul 15, 2024

The same Jean Klingler did this other one for streams

Screenshot 2024-07-15 at 17 55 26

To be tested!

@nelsonic
Copy link
Member

Respectfully, I reject the "Elixir is hard" narrative as FUD. 🙅
Doing anything at an expert level is harder than most beginners think. 💭
The amount of horrible JS code I've read (and had to refactor) over the years makes me cry inside! 😢 ⏳

Newsflash: Go is always going to be faster than Elixir on synthetic benchmarks! 📰
But then you need a whole other infrastructure to run and monitor the Go App.
Which requires a DevOps person/team ... 💰

Elixir / Erlang wasn't made for manipulating data structures ...
It's like using a hammer to dig a hole; pointless. 🔨 🤦‍♂️
Erlang (BEAM) bytecode runs in a VM, Go is compiled to a binary.

The data structures / manipulation and dynamic types arguments are a good reason to reach for Zig
Which beats Go in most cases: https://github.com/hanabi1224/Programming-Language-Benchmarks
Specifically: https://programming-language-benchmarks.vercel.app/go-vs-zig

Chris Ertel's "The Hitchhiker's Guide to Elixir Performance" (linked above) is very insightful.
"There is no optimization without experimentation":

image

Ultimately, people need to know why they are using Elixir. 💧 ❤️
It's not for synthetic benchmark performance. 🙅
I see Elixir, Phoenix and LiveView as tools for rapid prototyping ideas.
Which can scale to millions of concurrent people using, as demonstrated by WhatsApp and Discord.
.then if there's a specific area of the App that is causing a bottleneck, it can be re-written later!

Getting started with Elixir is what matters. 🔰
And for that I find the language is very beginner-friendly. 👌

@njwest
Copy link

njwest commented Jul 16, 2024 via email

@ndrean
Copy link
Contributor Author

ndrean commented Jul 16, 2024

I knew that "hard" would be provocative but I did it is an positive way. I like Elixir. Probably needs a disclaimer. The idea is not to show how bad Elixir is at manipulating data. On the contrary, because you are using a functional language with immutable data, you should be aware of this and challenge yourself - applying this to myself and not spread poor code - and it is shown above that solutions exist, internal or external.

I learned ordsets and will try to use it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants