DEV Community

Robin Heggelund Hansen
Robin Heggelund Hansen

Posted on

53 8 1

Elm 0.19 brings better collections

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.

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (2)

Collapse
 
nikican profile image
niki
Collapse
 
bernardoow profile image
Bernardo Gomes

Great!

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay