Structural sharing
Structural sharing is a technique in which multiple data-structure versions reuse unchanged internal components rather than copying them.
Data-Oriented Programming: Reduce software complexity
Structural sharing is a data-management technique in which related versions reuse unchanged portions of the same underlying structure.
- How it is used
- Creates immutable state versions efficiently while supporting calculation, commit, history, undo, and time travel.
- How deep it goes
- Explains path copying, recursive implementation, persistent structures, and linked-list sharing, while deferring concurrent mutations.
- Examples
- Uses a library catalog update, recursive JavaScript code, linked lists, historical state versions, and Lodash FP.
- What you can do after
- Build it from scratch with recursive path copying, apply it through Lodash FP, and implement simple undo with version references.
Read how Data-Oriented Programming: Reduce software complexity explains structural sharing →
Grokking Simplicity
Structural sharing is a data-structure technique in which multiple versions reuse references to common portions of their representation.
- How it is used
- Uses copy-on-write to update nested immutable data without copying unchanged objects.
- How deep it goes
- Explains shallow copies, shared references, nested update paths, and safety, while deferring specialized persistent structures.
- Examples
- Demonstrates shopping-cart price and quantity updates using array slices, Object.assign(), and nested replacement.
- What you can do after
- Apply via JavaScript’s slice() and Object.assign() to implement copy-on-write updates for nested data.
Functional Programming in Scala, Second Edition
Structural sharing is the reuse of unchanged substructures between immutable data structures instead of copying them.
- How it is used
- Preserves immutable list values while avoiding unnecessary copying during functional updates.
- How deep it goes
- Explains reuse, persistence, runtime costs, and copying limits through linked-list operations, but defers alternative data-structure implementations.
- Examples
- Uses Cons and Nil lists, tail, drop, dropWhile, append, and init to expose reuse and copying behavior.
- What you can do after
- Apply structural sharing by implementing immutable list operations that reuse available substructures and copy only necessary prefixes.
Read how Functional Programming in Scala, Second Edition explains structural sharing →
Also covered in
What to know first
- functional programmingFunctional programming is a programming paradigm that expresses computation through the evaluation and composition of functions, typically favoring immutable data and minimizing mutable state and side effects.
- deep copyA deep copy is a recursive duplicate of an object or data structure that copies its nested contents rather than sharing them with the original.
- arrayAn array is an ordered collection of elements organized in one or more dimensions and accessible by position or index.
- treeA tree is a connected, acyclic structure of nodes organized through parent-child relationships, typically around a single root.
Related concepts
- persistent data structureused by · A persistent data structure preserves access to earlier versions when updates produce new versions rather than modifying existing ones.
- shallow copyproduced by · A shallow copy creates a new outer data structure while retaining references to its nested values rather than copying them recursively.
- immutable collectionuses · An immutable collection is a collection whose contents cannot be changed after it is created.
- multi-version state managementproduces · Multi-version state management maintains multiple immutable versions of system data and advances a reference to select the current version.
- hierarchyuses · A hierarchy is an organization of entities into levels or nested groups connected by parent-child, containment, or broader-to-narrower relationships.
- treeused by · A tree is a connected, acyclic structure of nodes organized through parent-child relationships, typically around a single root.
Questions about structural sharing
What is structural sharing?
Structural sharing is a technique in which multiple data-structure versions reuse unchanged internal components rather than copying them.
Which Manning books explain structural sharing?
Data-Oriented Programming: Reduce software complexity, Grokking Simplicity and Functional Programming in Scala, Second Edition.
What should I know before learning structural sharing?
Manning books that teach structural sharing usually introduce functional programming, deep copy, array and tree first.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.


