Using Rust with Elixir for code reuse and performance
11–20 of 20 posts
Re: Using Rust with Elixir for code reuse and performance
#12That seems very surprising to me. Is this a common result? I've heard that the BEAM is not the best for "number crunching" code, is this one of those scenarios? Is this really just the raw performance of the languages, or a difference in algorithms? There's also no mention of the version of Elixir and the OTP. Did the JIT change anything?
Re: Using Rust with Elixir for code reuse and performance
#13One thing to keep in mind is that even the simplest Rust NIF will significantly slow your builds and increase your repo/artifact sizes.
Re: Using Rust with Elixir for code reuse and performance
#14One thing to keep in mind is that even the simplest Rust NIF will significantly slow your builds and increase your repo/artifact sizes.
Re: Using Rust with Elixir for code reuse and performance
#15For someone who does not know much about NIFs, will it be a lot slower if the Rust service is coded as a command line application and then invoked using System.cmd? Is that a good alternative?
Re: Using Rust with Elixir for code reuse and performance
#16> Unsurprisingly, Rust outperforms Elixir by 2 orders of magnitude. That seems very surprising to me. Is this a common result? I've heard that the BEAM is not the best for "number crunching" code, is this one of those scenarios? Is this really just the raw performance of the languages, or a difference in algorithms? There's also no mention of the version of Elixir and the OTP. Did the JIT change anything?
Based on performance numbers I've seen, I'd expect a one-order-of-magnitude difference to be a more common case in general.
Re: Using Rust with Elixir for code reuse and performance
#17One thing to keep in mind is that even the simplest Rust NIF will significantly slow your builds and increase your repo/artifact sizes.
Re: Using Rust with Elixir for code reuse and performance
#18> Unsurprisingly, Rust outperforms Elixir by 2 orders of magnitude. That seems very surprising to me. Is this a common result? I've heard that the BEAM is not the best for "number crunching" code, is this one of those scenarios? Is this really just the raw performance of the languages, or a difference in algorithms? There's also no mention of the version of Elixir and the OTP. Did the JIT change anything?
The BEAM VM is amazing at many things but it is still a VM and while the BeamAsm Just In Time compiler added in 2020 can offer performance improvement gains of 130%, there are areas where the BEAM still won't outperform native code.
Erlang excels at network programming and binary data processing. Computation intensive math and heavy string processing are both good NIF use cases.
An article on string performance [1],pre-JIT, describes initial Elixir benchmark of 140s vs C's 3.74s. They managed to make a number of tradeoffs and get the Elixir benchmark improved to 13s. Part of how they did that was to not use unicode (IO.binstream instead of IO.stream), that alone gained them ~4s.
[1] https://blog.jola.dev/elixir-string-processing-optimization
Re: Using Rust with Elixir for code reuse and performance
#19For someone who does not know much about NIFs, will it be a lot slower if the Rust service is coded as a command line application and then invoked using System.cmd? Is that a good alternative?
It will be faaaar slower. If it is a good alternative depends on your need. Benchmark your situation