Better immutability
Faster immutable updates
A JavaScript library for efficient immutable updates. Write plain mutations on a draft, and get the next immutable state.
Time for the same updates
Shorter is better
- Mutative1x
- Immer3.6x
- Immer, auto-freeze6.6x
Simple
Immutable updates without the spread
Mark the last item of a list as done and add a new one. With spread syntax, you copy each level of the state yourself; with Mutative, you change a draft.
Spread syntax
const nextState = {
...state,
list: [
...state.list.slice(0, 2),
{
...state.list[2],
done: true,
},
{ text: 'Learn Mutative', done: true },
],
};With Mutative
import { create } from 'mutative';
const nextState = create(state, (draft) => {
draft.list[2].done = true;
draft.list.push({ text: 'Learn Mutative', done: true });
});Fast
Faster than Immer, by design
Mutative copies each object at most once per update and moves array elements natively on its copy, instead of through a draft proxy.
3.6x
Faster than Immer with matched settings
Faster in 595 of 614 measured cases
6.6x
Faster than Immer with each library's defaults
Faster in 154 of 157 measured cases
97
Benchmarked workloads
Every result checked against hand-written reducers
Time per update, relative to Mutative
Shorter is better
- Mutative
- Immer
- Immer, auto-freeze
200 RTK Query-style updates
100 pending and 100 resolved requests
1.1x faster
Update one field of a small object
A tiny plain object
1.4x faster
Add a number to a Set
A Set of 10,000 numbers
31x faster
Remove the first row
An array of 10,000 rows, with shift()
1,052x faster
| Workload | Mutative | Immer | Immer, auto-freeze | Faster than Immer |
|---|---|---|---|---|
| 200 RTK Query-style updates100 pending and 100 resolved requests | 1,001 µs | 1,133 µs | 4,795 µs | 1.1x |
| Update one field of a small objectA tiny plain object | 0.51 µs | 0.69 µs | 0.95 µs | 1.4x |
| Add a number to a SetA Set of 10,000 numbers | 29.5 µs | 904 µs | 975 µs | 31x |
| Remove the first rowAn array of 10,000 rows, with shift() | 7.04 µs | 7,408 µs | 8,137 µs | 1,052x |
The factors of the cards are geometric means of Immer's time over Mutative's across all 97 workloads. See the benchmarks
In production
From Immer to Mutative
Open-source projects that replaced Immer with Mutative, in their own words.
“Using mutative instead of immer, this has reduced the main thread scripting by about 1 second.”
Replaced Immer with Mutative in its client.
Admin panels, internal tools and dashboards
Pull request, February 2025“Mutative is about 3ms on a single transaction.”
With Immer, a single transaction took about 8 ms, and about 40 ms as pending transactions were added.
A backend with auth, permissions, storage and presence
Pull request, September 2024“…you'll notice slight improvements in app responsiveness.”
Replaced Immer with Mutative in version 3.0.11.
An end-to-end encrypted note-taking app
Release notes, July 2024“All plugin stores now use zustand-mutative for immutable state updates, which is faster than immer.”
Moved its plugin stores to zustand-mutative in version 42.
A rich-text editor for React
Release, January 2025Also used by Mol*, OpenRewrite and MSW Data. See who uses Mutative
Features
Everything immutable updates need
Drafts for every data structure, with patches, freezing, marks and strict mode when you need them.
Mutation makes immutable updates
Immutable updates of objects, arrays, Sets and Maps, written as mutations of a draft.
High performance
About 6.6x faster than Immer out of the box, and faster than hand-written spreads for objects with thousands of keys.
Optional freezing
No freezing of immutable data by default, and auto-freeze when you want it.
JSON Patch
Patches and inverse patches of each update, which can be JSON Patch operations.
Custom shallow copy
Your own shallow copy for more types of immutable data, such as class instances.
Non-invasive marking
Mark immutable and mutable data without changing its structure.
Strict mode
Explicit reads of data that is not drafted, which a recipe could otherwise change in place.
Reducers
Producers that work as reducers, with Redux and any other immutable state library.
Ecosystem
Works with your stack
Libraries built on Mutative for React, Zustand, Jotai, XState, Yjs and more.
Ready to try Mutative?
Learn the most important Mutative concepts in 5 minutes.