Understanding Clojure's Persistent Vectors, pt. 1

April 15, 2026
Close-up of a man's hand playing a game of Jenga, focusing on skill and precision.
Photo by ANTONI SHKRABA production on Pexels

The gist

A 2013 blog post on Hypirion revisits the guts of Clojure’s persistent vectors — the data structure Rich Hickey popularized (influenced by Phil Bagwell’s work). It has been reported that these vectors provide practically O(1) runtime for appends, updates, lookups and subvec; importantly, they’re persistent, so every modification allegedly produces a new vector rather than mutating the old one. Sound magical? It isn’t magic. It’s a clever tradeoff: structural sharing, low copying, and a tree-based representation.

How the mechanics work

The post walks readers through a simple tree model to teach the core idea. Instead of a flat, mutable array that must be copied on change, Clojure’s vector is represented as a balanced, ordered tree where leaves hold elements and interior nodes point to subnodes. To change a value you don’t rewrite the whole thing — you do path copying: copy the nodes along the route to the target leaf, change the leaf, and return a new root that shares most of its structure with the old one. The author uses a small example (replacing element 5 with 'beef' via assoc) to make the “share most, copy little” pattern click.

Why it matters

Why should any of this tug at your brain? Because immutability and performance often feel like oil and water. Persistent vectors show they can mix. Structural sharing gives you snapshots that act a lot like Git’s commit trees: efficient, compact, and safe to keep around. For functional programmers and systems that value immutability — think modern reactive UIs or concurrent services — that’s a big deal.

What’s next

This installment sticks to the basics: updates, appends and pops. The post promises deeper dives — tails, transients and practical optimizations that Clojure adds on top of the core idea — in later entries. If you ever wanted to see how persistence is done without throwing performance under the bus, this piece is a neat, approachable starting point.

Sources: hypirion.com, Hacker News