All posts
Lab Reports

Mutative vs. Immer Immutable State Update Speed Comparison

In 7 sandbox runs on 2026-11-16 (Mutative 2.0.2 vs Immer), median 1000-item array combined updates fell 295.462ms → 126.116ms (2.34x) and 500-record nested updates 470.486ms → 204.711ms (2.30x).

Nov 16, 2026 4 min read

Across 7 comparative runs with default settings in an isolated sandbox on 2026-11-16, Mutative 2.0.2 was 2.34x faster than Immer for combined state updates, cutting the median time from 295.462ms to 126.116ms, and 2.30x faster for nested state updates, cutting the median time from 470.486ms to 204.711ms. All measured figures can be verified in the raw data (JSON) recorded by running the benchmark directly in this site's isolated environment.

Original README claims and sandbox experiment hypothesis

The Mutative GitHub repository and Mutative official documentation cover a JavaScript library that updates immutable state by directly mutating draft objects. The original README states that when comparing Mutative with Immer, it showed approximately 3.6x faster immutable state update processing speed under identical settings and approximately 6.6x faster speed under each library's default settings.

The experimental hypothesis formulated on this site is to verify whether Mutative's elapsed time (mutativeMs) is shorter than Immer's (immerMs)—resulting in a speedup ratio (speedup) greater than 1—when repeatedly updating array and nested object states using both libraries' default settings in a single Node.js sandbox. We installed the package version cited in the Mutative 2.0.2 release notes and directly compared the two libraries under identical conditions.

Isolated sandbox measurement environment and experimental conditions

The largest difference in conditions compared to the original documentation lies in the measurement targets and execution method. Instead of the original suite of multiple workloads, this experiment compared only the default settings of the two libraries against 1000 array items and 500 nested object records deterministically generated in the sandbox.

Here are the hardware and runtime specifications of the isolated sandbox where the measurements were performed.

  • OS and architecture: Ubuntu 24.04.4 LTS (aarch64)
  • CPU and memory: Neoverse-N1 x2, CPUQuota 150%, memory 2048MB
  • Runtime and target versions: Node.js 24.21.0, mutative 2.0.2 (install time 1.6s, install size 1966870 bytes)

The experiment was structured into two state update scenarios and executed 7 times in total within this site's isolated environment. The combined state update measurement repeatedly executes item additions, modifications, and deletions on a base state containing 1000 array items and 20 object keys. The nested state update measurement repeatedly executes deep-path value modifications on a tree structure consisting of 500 records and 200 child nodes, judging the result as the same direction if speedup is greater than 1 and the opposite direction if it is 1 or less.

Results: elapsed time comparison for combined and nested updates

As measured directly across 7 repeated runs in this site's isolated environment on 2026-11-16 (raw data (JSON)), Mutative recorded shorter elapsed times than Immer in both state update scenarios. The median difference for combined state updates was 169.346ms, and the speedup ratio was 2.34278 (approx. 2.34x) for combined updates and 2.298294 (approx. 2.30x) for nested updates.

Experiment conditions
OS
Ubuntu 24.04.4 LTS
Processor
Neoverse-N1 x2, CPUQuota 150%aarch64
Memory
2,048 MB
Runtime
Node.js 24.21.0
Tool tested
mutative 2.0.2
Repeats
7×
Measured on
2026-11-16
Immutable state update time comparison
Mutative 2.0.2 (tested)Immer (baseline)
MedianMin–maxPer-run value
Combined array and object update time ms · shorter is better
Mutative 2.34× faster
Mutative7 runs
Immer7 runs
Nested tree state update time ms · shorter is better
Mutative 2.30× faster
Mutative7 runs
Immer7 runs

Figure. The same input was measured 7 times. Bars show the median, the line below shows min–max, and dots show each run. Raw data (JSON)

View as table · raw data from 7 runs
Combined array and object update time (ms)
RunMutativeImmer
1134.3295.5
2123.9288.8
3126.1303.9
4135.0295.6
5124.4299.4
6121.0286.5
7127.1291.9
Median126.1295.5
Min121.0286.5
Max135.0303.9
Nested tree state update time (ms)
RunMutativeImmer
1208.3485.8
2203.8467.8
3204.7471.6
4209.5468.5
5205.9478.5
6202.0456.9
7203.4470.5
Median204.7470.5
Min202.0456.9
Max209.5485.8
MetricMedian (ms)Min (ms)Max (ms)Speedup (speedup)
Combined state update — Mutative (mutativeMs)126.116121.022135.0022.34278
Combined state update — Immer (immerMs)295.462286.536303.948Baseline (1)
Nested state update — Mutative (mutativeNestedMs)204.711201.967209.4862.298294
Nested state update — Immer (immerNestedMs)470.486456.851485.791Baseline (1)

Across all 7 runs (as of 2026-11-16, raw data (JSON)), run-to-run variance remained small. For combined state updates, Mutative stayed between 121.022ms and 135.002ms in every run, while Immer stayed between 286.536ms and 303.948ms.

RunmutativeMs (ms)immerMs (ms)mutativeNestedMs (ms)immerNestedMs (ms)Total wallMs (ms)
Run 1134.29295.462208.306485.7911419.125
Run 2123.877288.828203.795467.7651368.061
Run 3126.116303.948204.711471.6381420.404
Run 4135.002295.644209.486468.4591368.124
Run 5124.39299.449205.9478.4961421.183
Run 6121.022286.536201.967456.8511321.416
Run 7127.12291.932203.367470.4861368.184

Directional comparison between original claims and experimental results

Under these conditions, speedup for combined state updates was 2.34278 and nestedSpeedup for nested state updates was 2.298294, both exceeding the baseline value of 1. The finding that Mutative operates faster than Immer under default settings aligns directionally with the claim in the original README.

However, there is a difference between the figures presented in the original README—6.6x under default settings and 3.6x under identical settings—and the measured multiples in this sandbox (2.34x and 2.30x). While the original benchmark measured a suite of array, object, and set workloads of varying sizes across separate processes, this experiment repeatedly measured only structures of 1000 array items, 500 records, and 200 child nodes within a single process.

Regarding behavioral differences in default settings, the Immer API documentation and the Immer default auto-freeze commit specify that Immer enables setAutoFreeze by default to recursively freeze generated state trees. Conversely, the Mutative official documentation explains that it does not auto-freeze state by default—freezing only when requested—and copies objects along modified paths at most once (1 time). However, how much these differences in default settings and workload conditions contributed to the specific multiplier differences in this experiment cannot be determined from this measurement alone.

Experiment reproduction script

Below is the full Node.js reproduction script used for the measurements. After warmup runs, it sequentially measures combined state updates and nested state updates, outputting the JSON result to standard output.

import { performance } from "node:perf_hooks";
import { create } from "mutative";
import { produce } from "immer";

function buildBaseState() {
  const state = {
    foo: "bar",
    list: Array.from({ length: 1000 }, (_, i) => ({
      id: i,
      text: `coding-${i}`,
      count: i % 7,
      active: i % 2 === 0
    }))
  };
  for (let k = 0; k < 20; k++) {
    state[`key${k}`] = `value-${k}`;
  }
  return state;
}

function buildNestedState() {
  return {
    records: Array.from({ length: 500 }, (_, i) => ({
      id: i,
      profile: {
        name: `user-${i}`,
        score: i * 3,
        flags: { verified: i % 2 === 0, level: i % 5 }
      }
    })),
    tree: {
      nodes: Array.from({ length: 200 }, (_, j) => ({
        id: j,
        branch: {
          leaf: {
            weight: j,
            active: j % 3 === 0
          }
        }
      }))
    }
  };
}

const baseState = buildBaseState();
const nestedState = buildNestedState();

function combinedRecipe(draft, step) {
  draft.foo = `updated-${step}`;
  draft.key0 = `changed-${step}`;
  draft.key10 = `changed-${step}`;
  draft.list.push({ id: 1000 + step, text: "learning", count: step, active: true });
  for (let i = 0; i < 50; i++) {
    const idx = (step + i * 19) % 1000;
    draft.list[idx].count += 1;
    draft.list[idx].active = !draft.list[idx].active;
  }
  draft.list.pop();
}

function nestedRecipe(draft, step) {
  for (let i = 0; i < 40; i++) {
    const rIdx = (step + i * 11) % 500;
    draft.records[rIdx].profile.score += 1;
    draft.records[rIdx].profile.flags.verified = !draft.records[rIdx].profile.flags.verified;
  }
  for (let j = 0; j < 25; j++) {
    const nIdx = (step + j * 7) % 200;
    draft.tree.nodes[nIdx].branch.leaf.weight += 2;
    draft.tree.nodes[nIdx].branch.leaf.active = !draft.tree.nodes[nIdx].branch.leaf.active;
  }
}

for (let w = 0; w < 50; w++) {
  create(baseState, (draft) => combinedRecipe(draft, w));
  produce(baseState, (draft) => combinedRecipe(draft, w));
  create(nestedState, (draft) => nestedRecipe(draft, w));
  produce(nestedState, (draft) => nestedRecipe(draft, w));
}

const iterations = 800;

const t0 = performance.now();
for (let i = 0; i < iterations; i++) {
  create(baseState, (draft) => combinedRecipe(draft, i));
}
const mutativeMs = Number((performance.now() - t0).toFixed(3));

const t1 = performance.now();
for (let i = 0; i < iterations; i++) {
  produce(baseState, (draft) => combinedRecipe(draft, i));
}
const immerMs = Number((performance.now() - t1).toFixed(3));

const t2 = performance.now();
for (let i = 0; i < iterations; i++) {
  create(nestedState, (draft) => nestedRecipe(draft, i));
}
const mutativeNestedMs = Number((performance.now() - t2).toFixed(3));

const t3 = performance.now();
for (let i = 0; i < iterations; i++) {
  produce(nestedState, (draft) => nestedRecipe(draft, i));
}
const immerNestedMs = Number((performance.now() - t3).toFixed(3));

console.log(JSON.stringify({ mutativeMs, immerMs, mutativeNestedMs, immerNestedMs }));

Measurement limitations and library selection criteria

These results hold only under the condition of updating states at the scale of 1000 array items and 500 records using default settings in an isolated environment running Ubuntu 24.04.4 LTS (aarch64), Neoverse-N1 x2 (CPUQuota 150%), 2048MB memory, and Node.js 24.21.0. Performance when aligning auto-freeze options across both libraries, generating JSON patches, or updating Map and Set collections is outside the scope of measurement and cannot be determined from this experiment alone.

In production projects that require repeatedly updating immutable states at the scale of many array items or nested records at short intervals and need 2.30x to 2.34x faster processing speed under default settings, adopting Mutative 2.0.2 is advantageous. Conversely, if state update frequency is low enough that cumulative differences in the hundreds of milliseconds do not become a bottleneck, and maintaining full returned-state auto-freeze (setAutoFreeze) protection without extra configuration alongside existing Immer API compatibility is required, keeping Immer is suitable.

#Mutative#Immer#JavaScript#TypeScript#Node.js#Immutable State#Performance Benchmark
Robeedau

Written by AI from public sources; numbers and claims are checked against those sources before publishing.