Qqwy

Qqwy

TypeCheck Core Team

Would there be interest in a Persistent Vector datatype?

Just now I came across Understanding Persistent Vectors, which describes how Clojure implements a vector-type, which for many operations allows faster access to its elements than a linked list.

I think this is very interesting, and an implementation of this in Rust exists (which was how I found it in the first place).

Now I am wondering: Are there people besides me that think it would be great to have a fast, indexable ordered container? I think it would be relatively straightforward to wrap the Rust library using Rustler.

What do you think? An alternate approach would be to implement the logic directly in Elixir, but that would probably be a couple of magnitudes slower.

In any case, I did not know that it was possible to create persistent vectors before (and okay, under the hood they are implemented using special balanced binary trees, so access is O(log32 n) instead of O(1) for mutable vectors), so I thought this might be interesting for not just me but you all as well :slight_smile: .

Most Liked

orestis

orestis

Having persistent vectors would be very cool indeed — but I wonder how this would work with the “shared nothing” memory of the BEAM?

Since this is all immutable data, you could have all of it in shared memory, and just send references to processes. But if you have to copy the entire tree every time you send it, it will quickly become very slow.

Interestingly enough, according to this, the Erlang Map implementation is based on Rich Hickey’s work. So you could probably just use the maps to simulate a persistent vector without going to Rust at all.

Qqwy

Qqwy

TypeCheck Core Team

An implementation of vectors/arrays built on top of maps is already available in the arrays package that is available on Hex.

I haven’t benchmarked them yet, but I’d expect them to usually be faster than Erlang’s :array implementation (which above library also has a wrapper for), because that one was built before maps were a thing.

As for tree copying: Copying a whole tree only adds log(n) elements to be copied to a process that would take n elements in the case of a sequential container structure like a list, so this is not ‘quickly becoming slow’ because the copying still happens in O(n) time complexity.

But we could benchmark this stuff at some point, I guess :grinning:

NobbZ

NobbZ

I haven’t followed your links. But when I read the last time about clojures vectors they where described as a linked list of chunks. And as of such had a read of about O(n/chucnk size) (which is theory equal to O(n) but feels faster).

But you say balanced tree, and then :array comes to my mind. Its not binary, but finger/rose tree, but still kind of balanced.

Where Next?

Popular in Discussions Top

jswny
I would like to better understand what the advantages/disadvantages of umbrella applications are compared to structuring your app as as s...
New
Fl4m3Ph03n1x
Background This question comes mainly from my ignorance. Today is Black Friday, one of my favorite days of the year to buy books. One boo...
New
praveenperera
How We Replaced React with Phoenix By: Thought Bot
New
AstonJ
I’ve just started the Phoenix part of the utterly brilliant online course by @pragdave. On generating the Phoenix app he uses the --no-ec...
New
IVR
Hi all, I’ve seen a number of related threads in the past, but I’d still be very curious to hear an up-to-date opinion on this topic. I...
New
AstonJ
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition) It’s been a while since we first asked this, I...
208 31142 143
New
restack_oslo
Hello, Please pardon me for any faux paux. I am 46 and this is my first time on a forum of any kind. I wanted to to get answers from tho...
New
RudManusachi
What configs will make sense to put to runtime.exs? – A bit of how I configure apps: I have generic configs in config/config.exs, dev...
New
chulkilee
Here are the list of HTTP client libraries/wrappers, and some thoughts on HTTP client in general. I’d like to hear from others how they w...
New
AstonJ
Can you believe the first professionally published Elixir book was published just 8 years ago? Since then I think we’ve seen more books f...
New

Other popular topics Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 53690 245
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
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
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 forese...
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
Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 126479 1222
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New

We're in Beta

About us Mission Statement