liveBook · Manning

Persistent list

As explained in Data-Oriented Programming: Reduce software complexity

A persistent list is an immutable list whose earlier versions remain available after elements are added or updated.

A persistent list is immutable: adding or updating elements creates a new version while preserving every earlier version. Rather than copying the entire collection, implementations use structural sharing, allowing versions to reuse unchanged data safely. section 9.5

The split that changes the cost

Suppose a list contains 100,000 elements. Splitting it repeatedly until pieces contain at most two elements gives a tree about 17 levels deep, so accessing or updating an element takes roughly 17 operations. Increasing the branching factor from 2 to 32 reduces the depth to about 3.3 levels. The asymptotic cost remains logarithmic, but the practical access cost drops substantially. section 9.2

Figure 9.1 Structural sharing with linked lists

Structural-sharing diagrams make the relationship between list versions visible: unchanged portions can be reused while each version remains available. section 9.2

The practical design principles are:

  • Keep data immutable so versions can share internal structure safely. section 9.5
  • Prefer a higher branching factor when access and update depth matter; the implementation described uses 32. section 9.2 section 9.5
  • Use an existing library when appropriate; Paguro collections implement read-only Java collection interfaces without allowing mutation through those methods. section 9.5

How Data-Oriented Programming: Reduce software complexity covers it

How deep it goes
Explains tree depth, branching factor, operation counts, and practical performance, then stops short of implementation code.
Examples
Uses 25,000-element copying, 100,000-element lists, repeated splitting, and branching factors of 2 and 32.
What you can do after
Evaluate persistent-list performance by relating access and update costs to tree depth and branching factor.
How it connects
Connects persistent lists with immutability, structural sharing, trees, branching factors, and Java collection interfaces.

Also explained in

Compare how 2 books explain persistent list →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data-Oriented Programming: Reduce software complexity. The section links point to the parts of the book it draws on.