loading...

Elm 0.19 brings better collections

skinney profile image Robin Heggelund Hansen ・2 min read

You're probably aware of this already but Elm 0.19 has just been released. When you read through the release notes and the documentation of the core library, you might to think that nothing has changed with regards to the built-in collection types: List, Array, Dict and Set.

You'd be wrong.

While it is true that the API remains entirely the same, there are huge changes under the covers which results in more performance, and a bug-free Array implementation. Let's take a closer look.

List

List is the data structure which have changed the least. In fact, the underlying data structure hasn't changed at all. The only thing which have changed is the implementation of List.foldr which is now faster by about 30%.

This alone might not seem to be that big of a deal, but considering map, filter and append are all implemented on top of foldr, this means that List is quite a bit faster across the board.

If you want to know more about the actual implementation, you can take a look at this PR.

Dict and Set

Dict has actually been re-written from scratch while retaining the original API. The benefits of this new implementation is mostly that of performance. We're talking 170% faster inserts and about 30% faster removals.

Set is just a thin wrapper around Dict, and so Set benefits from the new implementation as well.

More info in the PR and these development updates: #1, #2.

Array

Like Dict, Array has been totally re-written. The original code was in Javascript, and suffered from grave bugs that could cause runtime crashes and mutations. The new implementation is in mostly Elm, and all known bugs are fixed.

From a performance stand point, the implementation is faster in some cases, while slower in others. More information in this development update.

Summary

The API might be the same, however, a huge amount of work has been done to make these data structures better than ever before.

There is a similar story for the Random module, which has been re-implemented by Max Goldstein to be faster and more, you know, random. You can learn more by checking out this PR.

Posted on by:

Discussion

markdown guide