grufino

grufino

Most performant (and lazy) way to do an operation on 2 lists

Hello!

I am building a quite robust pipeline of operations that performs basically math of all types on thousands (in the future may be millions) of rows.

I would like to know what’s the most performant way to do something that’s been repeating on my code quite a lot, because I always have 2 different lists of variables and need to transform to one by using different types of formulas, so it can become a bottleneck, so a simple example of one case would look like this:

Stream.zip(axs, ays)
|> Stream.map(fn {ax, ay} -> Math.sqrt(ax + ay) end)

Where axs and ays would be lists of float numbers.

By the example you can already understand that it has to be lazy, because we plan to optimize the pipeline using Flow or some other concurrent tool when we have a first version, so advices in that direction are also welcome. :slight_smile:

Thanks in advance!

Most Liked

axelson

axelson

Scenic Core Team

I wouldn’t change from operating in one function to a Task based on the code complexity, instead that should be done based on the runtime behavior, for example if a function is parallelizable then it would make sense to use concurrency like a Task (or perhaps GenStage/Flow)

dimitarvp

dimitarvp

You are already doing it right IMO.

The only question that’s left is: do you really want to use Elixir for math? Definitely not its forte.

Alternatively, I’d just dump the two collections of numbers in a SQLite database and do the math operation with a SELECT statement. But it depends. If the two lists of data are huge and/or not guaranteed to zip together well then Elixir might be the better tool.

blatyo

blatyo

Conduit Core Team

The type of math mentioned in the original post seems perfectly fine for Elixir. The implementation of most functions on the math module are NIFs. The stuff that tends to be out of scope for Elixir are heavy math operations like calculating the dot product of two large matrices.

Where Next?

Popular in Questions Top

vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> somethi...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
chokchit
** (DBConnection.ConnectionError) connection not available and request was dropped from queue after 2733ms. You can configure how long re...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
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
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New

Other popular topics Top

KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36352 110
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
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
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39467 209
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement