Qqwy

Qqwy

TypeCheck Core Team

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: .

Showing Posts 1 to 6

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.

OvermindDL1

OvermindDL1

Yeah this was my thought. They based it on a balance of 10 as they found it to be the most efficient on the BEAM VM at the time the tests were done, but it is a tree, though not entirely balanced, however it is sparse-safe and fast (though depending on usage a map might be faster).

EDIT: Also :array is old, it is very likely that the BEAM VM would be optimized for better settings than what it does now too. That’d be an interesting test.

Qqwy

Qqwy OP

TypeCheck Core Team

And I believe :array is implemented completely in Erlang (rather than in C) (OTP source), which means that it is somewhat slower, and that the data structure is emulated using nested Erlang tuples, rather than using a thight internal tree representation.

mischov

mischov

I have missed Clojure’s persistent vectors (in Clojure they’re generally the go-to ordered collection instead of lists), but I would be hesitant to use them very widely if they’re not a core (BEAM) type.

I also don’t know how I’d feel about a widely used datatype in my application being at the mercy of Rustler not having ERTS-related compilation errors.

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 OP

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:

— All posts loaded —

Where Next? Top

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 92995 915
New
caslu
I want to open this thread for you all to discuss and help those who really like Ash but are still hesitant to use it in a real project. ...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
GES233
I’m posting this in response to Jose’s recent tweet (Cr. link) : People are sleeping on Elixir for a coding harness: Hot-code swappi...
New
_mfierro
Hello, I wrote Stop My Hand, a Scattergories-like web application using Phoenix/LiveView as my learning project for Elixir (after readin...
New
marciol
It would be helpful to have a list of companies worldwide that hire engineers without prior experience in Elixir. Often, it can be quite ...
New
durvia
Anyone running long-lived stateful processes on BEAM? We’re building an AI agent runtime and would love to compare notes. We’re a small ...
New

Other Trending Topics Top

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews