performance.md
This file
Path
docs/performance.md
21 lines · 1.7 KiB · Markdown
Last changed by
Docs websiteMichel Weststratebefore adoption6d903d1
History of this fileTake it
Docs WIPMichel Weststratebefore adoption12298be
lines 1–7why, one step back1---2id: performance3title: Immer performance4---56<div id="codefund"><!-- fallback content --></div>7Docs websiteMichel Weststratebefore adoption6d903d1
line 8why, one step back8Here is a [simple benchmark](https://github.com/immerjs/immer/blob/master/__performance_tests__/todo.js) on the performance of Immer. This test takes 50,000 todo items and updates 5,000 of them. _Freeze_ indicates that the state tree has been frozen after producing it. This is a _development_ best practice, as it prevents developers from accidentally modifying the state tree.Docs WIPMichel Weststratebefore adoption12298be
lines 9–13why, one step back910Something that isn't reflected in the numbers above, but in reality, Immer is sometimes significantly _faster_ than a hand written reducer. The reason for that is that Immer will detect "no-op" state changes, and return the original state if nothing actually changed, which can avoid a lot of re-renderings for example. Cases are known where simply applying immer solved critical performance issues.1112These tests were executed on Node 10.15.1. Use `yarn test:perf` to reproduce them locally.13Docs websiteMichel Weststratebefore adoption6d903d1
line 14why, one step back14Docs WIPMichel Weststratebefore adoption12298be
lines 15–21why, one step back1516Most important observation:1718- Immer with proxies is roughly speaking twice to three times slower as a handwritten reducer (the above test case is worst case, see `yarn test:perf` for more tests). This is in practice negligible.19- Immer is roughly as fast as ImmutableJS. However, the _immutableJS + toJS_ makes clear the cost that often needs to be paid later; converting the immutableJS objects back to plain objects, to be able to pass them to components, over the network etc... (And there is also the upfront cost of converting data received from e.g. the server to immutable JS)20- Generating patches doesn't significantly slow immer down21- The ES5 fallback implementation is roughly twice as slow as the proxy implementation, in some cases worse.