
Immer: immutable and persistent data structures for C++ - ingve
https://github.com/arximboldi/immer
======
arximboldi
Author here, open for questions :)

~~~
rawnlq
How much does immutability/persistence cost in terms of performance and
memory? Are there benchmarks against std::vector? E.g, are we talking about
10x or 100x slow down?

~~~
arximboldi
Performance is one of the goals, so I am benchmarking everything. I run
benchmarks on Travis, locally on my machine, and sometimes on a Raspberry Pi
3. You can check some of the reports here:
[https://public.sinusoid.es/misc/immer/reports/](https://public.sinusoid.es/misc/immer/reports/)
(this is a bit hard to interpret without further comment).

So, the slowdown depends on the operation.

At the moment, comparing `immer::vector` to `std::vector`, example, for
reading, using internal iteration (e.f. `for_each`) you get 1.5X, using
iterators something like 2.5X, using [] something like 6X iteratively,
something like 1.1 in random order.

Updating a single `int` element is like 100X. (This factor decreases with the
size of the updated element, though!) But then, for example, `push_back` is
only 1.1X std::list, and it does not rely on amortization, making it better
for latency. Considering that you get access time similar to std::vector and
persistence, it is a good deal. Also, with `flex_vector`, you get logarithmic
slicing and concatenation, making these operations _faster_ than for
std::vector (when using big-enough vectors). Also, I am working now on _batch
updates_ via transients, so if you update 10 elements in a row, you don't pay
10 times 100X (basically, you only pay the 100X once, which is very much ok
for most use-cases, think like a 1microsecond tax per mouse click ;)

There are lots of trade offs one can make (in general, one can make updating a
bit faster by making access a bit slower). Also, it depends a lot on the
memory management strategy, which can also be customized.

~~~
joatmon-snoo
Are the benchmarks supposed to look like this, with tooltips all the way at
the right?

[http://imgur.com/a/iY9hT](http://imgur.com/a/iY9hT)

I'm on Win7 x64 Chrome.

~~~
arximboldi
That's how they look for me too. I agree it makes it hard to see which bar is
what, but it makes it easy to scan all the results numbers in order.

------
santaclaus
> Postmodern immutable and persistent data structures for C++

What is a postmodern data structure?

~~~
Etheryte
They probably mean "trying to get on the hype train". I have nothing against
immutable data structures, but that wording is just silly.

~~~
arximboldi
It was meant as a half-joke picking on how everything is now "modern" on C++.

The half-serious part is that there has been a trend in the last few years in
the "modern" C++ community against Copy-On-Write, heap allocation, shared
pointers, etc. Immutability kind of brings new life to these concepts...

------
ScottBurson
If anyone is looking for something like this for Java, there are a few of
them, including my own FSet: [https://github.com/slburson/fset-
java](https://github.com/slburson/fset-java)

~~~
pvg
What are some of the others you know of?

~~~
axle_512
Another java library with persistent/immutable datastructures is javaslang.

