Skip to content

RTK with Immer x100 slower than vanilla Redux at average (up to x400) #4793

Open
@gentlee

Description

@gentlee

I've wrote some benchmarks trying to understand how Immer influences the redux performance and got some very strange results:

  • the worst case is RTK slower than vanilla Redux by 408 times, and at average it is slower by 100 times...
  • even using immutable approach with original doesn't make much difference.

There are probably some mistakes in this code (initially generated by AI), so appreciate some help to find that out.

Here is the code.

To run: NODE_ENV=production node --expose-gc benchmark.mjs

Environment:

  • Node v22.12.0
  • Mac M1 16Gb

Results:

Data, ms (the lower the better)
  Vanilla Immer Immer NoAutoFreeze Immer Immutable Immer Immutable NoAutoFreeze
Add Item 131.3 13450.59 11812.4 11857.97 26037.62
Remove Item 358.88 24837.13 23621.49 8038.03 7194.04
Update Item 423.92 15680.84 14181.17 9658.24 28933.6
Concat Array 120.51 49178.25 47117.22 10940.38 36005.91
[Average] 258.65 25786.7 24183.07 10123.66 24542.79
Data, x times slower (the lower the better)
  Vanilla Immer Immer NoAutoFreeze Immer Immutable Immer Immutable NoAutoFreeze
Add Item 1 102.44 89.96 90.31 198.31
Remove Item 1 69.21 65.82 22.4 20.05
Update Item 1 36.99 33.45 22.78 68.25
Concat Array 1 408.08 390.98 90.78 298.78
[Average] 1 99.7 93.5 39.14 94.89
Chart, x times slower

Image

PS.

  • Initially test array had 100,000 size, but decreased to 10,000 to be closer to the average apps. Results are for the second.
  • Immer means using RTK's configureStore and createSlice. Vanilla means using createStore from redux.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions