dwyl / learn-elixir

:droplet: Learn the Elixir programming language to build functional, fast, scalable and maintainable web applications!
1.61k stars 107 forks source link

Elixir is harder than you think #215

Open ndrean opened 1 month ago

ndrean commented 1 month ago

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

Some examples:

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

Screenshot 2024-07-15 at 15 36 04

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

ndrean commented 1 month ago

The same Jean Klingler did this other one for streams

Screenshot 2024-07-15 at 17 55 26

To be tested!

nelsonic commented 1 month ago

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 commented 1 month ago

I agree with Nelson here, especially around how it is much easier to write inefficient JS code than Elixir code.

I also take issue with the notion that Elixir is hard because of the inefficient way it accesses and manipulates lists. If a beginner somehow got themselves into a situation in which they actually had a tremendously long list to sort and search (and they’re not doing it at the database level for some reason), there are plenty of examples of how to work around this (e.g. https://discord.com/blog/using-rust-to-scale-elixir-for-11-million-concurrent-users )

JS and other langs have way more performance pitfalls, especially around data marshalling and data transmission — pitfalls that we don’t run into in Elixirland simply because the BEAM ecosystem is so mature.

IMHO it is also much easier to stand up networked Elixir apps than standalone Python or C apps… not to mention how easy it is to set up an Elixir app that can run and supervise Python/Rust/etc apps.

To me Elixir’s strength is in how flippin’ easy it is… as long as you’re not going crazy with sigils and captures, those will confuse people :P

Cheers, Nick

On Tue, Jul 16, 2024 at 12:31 AM Nelson @.***> wrote:

Respectfully, I reject the "Elixir is hard" narrative as FUD https://en.wikipedia.org/wiki/Fear,_uncertainty,_and_doubt. 🙅 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 https://github.com/dwyl/learn-zig/issues/1 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.png (view on web) https://github.com/user-attachments/assets/53bc044f-2279-4fe1-a6e1-8d4d5251f76a

Ultimately, people need to know why https://github.com/dwyl/learn-elixir/issues/102 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. 👌

— Reply to this email directly, view it on GitHub https://github.com/dwyl/learn-elixir/issues/215#issuecomment-2229998869, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA4RWIBSTUDL77IJUEVJC53ZMSO3NAVCNFSM6AAAAABK4ONC4SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMRZHE4TQOBWHE . You are receiving this because you are subscribed to this thread.Message ID: @.***>

ndrean commented 1 month ago

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.