performance.md
This file
Path
docs/performance.md
39 lines · 3.0 KiB · Markdown
Last changed by
Added egghead.io video embedsMichel Weststratebefore adoptiona866760
History of this fileTake it
Merge pull request #421 from immerjs/docsMichel Weststratebefore adoption9be6e46
lines 1–7why, one step back1---2id: performance3title: Immer performance4---56<div id="codefund"><!-- fallback content --></div>7Added egghead.io video embedsMichel Weststratebefore adoptiona866760
lines 8–25why, one step back8<details>9 <summary style="color: white; background:#c200c2;padding:5px;margin:5px;border-radius:2px">egghead.io lesson 5: Leveraging Immer's structural sharing in React</summary>10 <br>11 <div style="padding:5px;">12 <iframe style="border: none;" width=760 height=427 src="https://egghead.io/lessons/react-profile-react-rendering-and-optimize-with-memo-to-leverage-structural-sharing/embed" ></iframe>13 </div>14 <a style="font-style:italic;padding:5px;margin:5px;" href="https://egghead.io/lessons/react-profile-react-rendering-and-optimize-with-memo-to-leverage-structural-sharing">Hosted on egghead.io</a>15</details>1617<details>18 <summary style="color: white; background:#c200c2;padding:5px;margin:5px;border-radius:2px">egghead.io lesson 7: Immer will try to re-cycle data if there was no semantic change</summary>19 <br>20 <div style="padding:5px;">21 <iframe style="border: none;" width=760 height=427 src="https://egghead.io/lessons/javascript-produces-immutable-data-and-avoid-unnecessary-creation-of-new-data-trees-with-immer/embed" ></iframe>22 </div>23 <a style="font-style:italic;padding:5px;margin:5px;" href="https://egghead.io/lessons/javascript-produces-immutable-data-and-avoid-unnecessary-creation-of-new-data-trees-with-immer">Hosted on egghead.io</a>24</details>25Merge pull request #421 from immerjs/docsMichel Weststratebefore adoption9be6e46
lines 26–37why, one step back26Here 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.2728Something 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.2930These tests were executed on Node 10.15.1. Use `yarn test:perf` to reproduce them locally.31323334Most important observation:3536- 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.37- 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)Merge pull request #443 from Mudassar045/fix-grammatical-typosMichel Weststratebefore adoption0349152
line 38why, one step back38- Generating patches doesn't significantly slow down immerMerge pull request #421 from immerjs/docsMichel Weststratebefore adoption9be6e46
line 39why, one step back39- The ES5 fallback implementation is roughly twice as slow as the proxy implementation, in some cases worse.