travitch / persistent-vector

Persistent vectors for Haskell based on array mapped tries
BSD 3-Clause "New" or "Revised" License
27 stars 4 forks source link

Get rid of empty constructor #7

Closed treeowl closed 3 years ago

treeowl commented 4 years ago

Having an Empty constructor prevents the root node from being unpacked. So for example, shoving six elements into the tail in one go will allocate six whole new root nodes on the heap, even though five of those are immediately garbage. The usual fix is just to make the empty value a zero-length slice of a zero-length array. To enhance sharing, there can be a single NOINLINE top-level empty sequence.