Jolt swaps red-black trees for B+trees and cuts peak memory by 40%
Swapping Jolt's sorted collections to a B+tree
Jolt's sorted-map and sorted-set, plus its java.util.TreeMap and TreeSet shims, now run on a persistent B+tree instead of a ported Clojure red-black tree. Packing up to 16 entries per leaf and 32 children per inner node shrinks a 4-million-entry tree from 22 levels to 5 and drops per-entry overhead from 48 bytes to 17. Peak memory fell from 1.73 GB to 1.04 GB, and most operations got faster at every size, though tiny collections built one insert at a time are about 15% slower.
Turns out that a red-black tree can indeed be swapped out for a B+tree here.
- kccqzy
Huh, I do not use sorted-map/sorted-set often but I would guess that they were already using B+trees. I guess I only remembered that Clojure vecs were backed by HAMTs, so I had assumed B+trees were also in use.
- codedokode
If you want to do large updates to B+tree, you better do it with bulk operations. I made a prototype on paper and in Python (unfinished, fails most of the tests) to do it. You provide a sorted list of deleted keys and sorted list of inserts and walk the B+ tree once, skipping unaffected branches and editing modified nodes. Not that difficult, but there are lot of small nuances. My prototype was using an immutable tree which adds some complexity.
- Stevvo
Taking the name of a popular physics engine for your lisp was not a good idea.