rogerdff

rogerdff

Best way to deal with immutability and to keep in memory a large list of structs where just 2 fields are frequently changed

I have to keep a large list of points in memory for real time access, after fetching the table from a DB.

Each point is a struct that has many fields, but just two fields will be changing: value and quality.

This list can grow over 100 thousand points.

The changes will occur every 1 second. And can affect many points, hundreds or even thorusands.

Since list is immutable, I can´t change an item in the list.

To avoid rebinding the whole list every second, I need to find a way to be able to deal with immutability.

I thought about keeping 3 parallel lists: 1 containg the fixed fields, 1 containing just the value field, 1 for the quality.

But that will let the design somehow awkward, cause I will have to do first a lookup in the fixed list to find the right point based on a address, and use that index position to change either the corresponding value and/or qualitty.

There must be a clever or simpler way to design it.

Hope someone has deal with such a problem.

Thanks for the attention.

Marked As Solved

dimitarvp

dimitarvp

Well, this is almost exactly what ETS is designed to solve? You can also use Elixir wrappers like Cachex and Ane.

Also Liked

dimitarvp

dimitarvp

Cachex is an amazing library. Every time I used it I’ve been very satisfied.

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

It sounds like what you want is a map, not a list. If you are doing index based updates you can do a map where the index is the key, and the value is the value. Updates to maps are memory efficient and do not require rebuilding the entire map.

:ets is another good choice as mentioned by @dimitarvp

Where Next?

Popular in Questions Top

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I fore...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "eq...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
nobody
Hi! In PHP: $SERVER['SERVERADDR'] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New

Other popular topics Top

AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
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
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 47849 226
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New

We're in Beta

About us Mission Statement