Arrays - Fast and versatile arrays with swappable implementations

I have some better news: Recently I was introduced to the Aja library, which implements multiple of data structures focused on performance. Its A.Vector is a persistent immutable array implementation, written fully in Elixir.

I wrapped A.Vector with the Arrays.Protocol (which was a breeze as Aja already exposes a very rich API :green_heart: ), and benchmarked them against the other implementations.

The results are amazing! :confetti_ball:

Aja’s implementation is fast. As can be seen from below benchmarking graphs, A.Vector beats the other alternative datatypes outright in most common tasks:

  • Random reads are much faster regardless of array size. (and remain super fast even for very large arrays!)
  • Random updates are slightly (~20%) slower than using an MapArray or ErlangArray for arrays with less than ~2^1 elements. After this, A.Vector is often much faster. (I do not yet know what causes the odd spike at 2^17 where A.Vector is super fast.)
  • Appending a single element is similarly performant to the other implementations. At higher sizes, it keeps up with ErlangArray (where MapArray becomes much slower.)
  • Concatenating is where A.Vector also really shines: It is roughly 5x(!) faster than ErlangArray and MapArray, regardless of collection size. It is only outclassed by plain lists (which are again ~5x faster for concatenation, but much (i.e. asymptotically) slower for all of the other three operations).

random_access_graphrandom_access_graph_log
random_element_update_graphrandom_element_update_graph_log
append_graphappend_graph_log
append_graph_log_focus
concat_graphconcat_graph_log
concat_graph_log_focusconcat_graph_loglog

You can find ArraysAja on GitHub in a separate library, of which v0.1.0 has been published to Hex.PM.

14 Likes