Skip to content
Myr

todo.js

This file

Path

__performance_tests__/todo.js

306 lines · 5.6 KiB · JavaScript

Last changed by

Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8

History of this file

Take it

The walk stopped after 200 commits: lines older than fbae585 point at it.

docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585

lines 1–3why, one step back
1"use strict"
23import {measure} from "./measure"

Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8

lines 4–8why, one step back
4import produce, {
5 setAutoFreeze,6 setUseProxies,7 enableAllPlugins8} from "../dist/immer.cjs.production.min.js"

docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585

lines 9–13why, one step back
9import cloneDeep from "lodash.clonedeep"
10import {List, Record} from "immutable"11import Seamless from "seamless-immutable"12import deepFreeze from "deep-freeze"13

Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8

lines 14–15why, one step back
14enableAllPlugins()
15

docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585

line 16why, one step back
16function freeze(x) {

Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8

lines 17–18why, one step back
17 Object.freeze(x)
18 return x

docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585

lines 19–29why, one step back
19}
2021const MAX = 5000022const MODIFY_FACTOR = 0.123const baseState = []24let frozenBazeState25let immutableJsBaseState26let seamlessBaseState2728// produce the base state29for (let i = 0; i < MAX; i++) {

Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8

lines 30–34why, one step back
30 baseState.push({
31 todo: "todo_" + i,32 done: false,33 someThingCompletelyIrrelevant: [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]34 })

docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585

lines 35–41why, one step back
35}
3637// Produce the frozen bazeState38frozenBazeState = deepFreeze(cloneDeep(baseState))3940// generate immutalbeJS base state41const todoRecord = Record({

Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8

lines 42–44why, one step back
42 todo: "",
43 done: false,44 someThingCompletelyIrrelevant: []

docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585

lines 45–53why, one step back
45})
46immutableJsBaseState = List(baseState.map(todo => todoRecord(todo)))4748// generate seamless-immutable base state49seamlessBaseState = Seamless.from(baseState)5051console.log("\n# todo - performance\n")5253measure(

Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8

lines 54–60why, one step back
54 "just mutate",
55 () => ({draft: cloneDeep(baseState)}),56 ({draft}) => {57 for (let i = 0; i < MAX * MODIFY_FACTOR; i++) {58 draft[i].done = true59 }60 }

docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585

lines 61–63why, one step back
61)
6263measure(

Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8

lines 64–71why, one step back
64 "just mutate, freeze",
65 () => ({draft: cloneDeep(baseState)}),66 ({draft}) => {67 for (let i = 0; i < MAX * MODIFY_FACTOR; i++) {68 draft[i].done = true69 }70 deepFreeze(draft)71 }

docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585

lines 72–74why, one step back
72)
7374measure("deepclone, then mutate", () => {

Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8

lines 75–78why, one step back
75 const draft = cloneDeep(baseState)
76 for (let i = 0; i < MAX * MODIFY_FACTOR; i++) {77 draft[i].done = true78 }

docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585

lines 79–81why, one step back
79})
8081measure("deepclone, then mutate, then freeze", () => {

Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8

lines 82–86why, one step back
82 const draft = cloneDeep(baseState)
83 for (let i = 0; i < MAX * MODIFY_FACTOR; i++) {84 draft[i].done = true85 }86 deepFreeze(draft)

docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585

lines 87–89why, one step back
87})
8889measure("handcrafted reducer (no freeze)", () => {

Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8

lines 90–96why, one step back
90 const nextState = [
91 ...baseState.slice(0, MAX * MODIFY_FACTOR).map(todo => ({92 ...todo,93 done: true94 })),95 ...baseState.slice(MAX * MODIFY_FACTOR)96 ]

docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585

lines 97–99why, one step back
97})
9899measure("handcrafted reducer (with freeze)", () => {

Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8

lines 100–108why, one step back
100 const nextState = freeze([
101 ...baseState.slice(0, MAX * MODIFY_FACTOR).map(todo =>102 freeze({103 ...todo,104 done: true105 })106 ),107 ...baseState.slice(MAX * MODIFY_FACTOR)108 ])

docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585

lines 109–111why, one step back
109})
110111measure("naive handcrafted reducer (without freeze)", () => {

Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8

lines 112–119why, one step back
112 const nextState = baseState.map((todo, index) => {
113 if (index < MAX * MODIFY_FACTOR)114 return {115 ...todo,116 done: true117 }118 else return todo119 })

docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585

lines 120–122why, one step back
120})
121122measure("naive handcrafted reducer (with freeze)", () => {

Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8

lines 123–132why, one step back
123 const nextState = deepFreeze(
124 baseState.map((todo, index) => {125 if (index < MAX * MODIFY_FACTOR)126 return {127 ...todo,128 done: true129 }130 else return todo131 })132 )

docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585

lines 133–135why, one step back
133})
134135measure("immutableJS", () => {

Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8

lines 136–141why, one step back
136 let state = immutableJsBaseState
137 state.withMutations(state => {138 for (let i = 0; i < MAX * MODIFY_FACTOR; i++) {139 state.setIn([i, "done"], true)140 }141 })

docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585

lines 142–144why, one step back
142})
143144measure("immutableJS + toJS", () => {

Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8

lines 145–151why, one step back
145 let state = immutableJsBaseState
146 .withMutations(state => {147 for (let i = 0; i < MAX * MODIFY_FACTOR; i++) {148 state.setIn([i, "done"], true)149 }150 })151 .toJS()

docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585

lines 152–154why, one step back
152})
153154measure("seamless-immutable", () => {

Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8

lines 155–159why, one step back
155 const state = seamlessBaseState
156 state.map((todo, index) => {157 if (index < MAX * MODIFY_FACTOR) return todo.set("done", true)158 else return todo159 })

docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585

lines 160–162why, one step back
160})
161162measure("seamless-immutable + asMutable", () => {

Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8

lines 163–169why, one step back
163 const state = seamlessBaseState
164 state165 .map((todo, index) => {166 if (index < MAX * MODIFY_FACTOR) return todo.set("done", true)167 else return todo168 })169 .asMutable({deep: true})

docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585

lines 170–172why, one step back
170})
171172measure(

Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8

lines 173–184why, one step back
173 "immer (proxy) - without autofreeze",
174 () => {175 setUseProxies(true)176 setAutoFreeze(false)177 },178 () => {179 produce(baseState, draft => {180 for (let i = 0; i < MAX * MODIFY_FACTOR; i++) {181 draft[i].done = true182 }183 })184 }

docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585

lines 185–187why, one step back
185)
186187measure(

Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8

lines 188–199why, one step back
188 "immer (proxy) - with autofreeze",
189 () => {190 setUseProxies(true)191 setAutoFreeze(true)192 },193 () => {194 produce(frozenBazeState, draft => {195 for (let i = 0; i < MAX * MODIFY_FACTOR; i++) {196 draft[i].done = true197 }198 })199 }

docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585

lines 200–202why, one step back
200)
201202measure(

Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8

lines 203–218why, one step back
203 "immer (proxy) - without autofreeze - with patch listener",
204 () => {205 setUseProxies(true)206 setAutoFreeze(false)207 },208 () => {209 produce(210 baseState,211 draft => {212 for (let i = 0; i < MAX * MODIFY_FACTOR; i++) {213 draft[i].done = true214 }215 },216 function() {}217 )218 }

docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585

lines 219–221why, one step back
219)
220221measure(

Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8

lines 222–237why, one step back
222 "immer (proxy) - with autofreeze - with patch listener",
223 () => {224 setUseProxies(true)225 setAutoFreeze(true)226 },227 () => {228 produce(229 baseState,230 draft => {231 for (let i = 0; i < MAX * MODIFY_FACTOR; i++) {232 draft[i].done = true233 }234 },235 function() {}236 )237 }

docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585

lines 238–240why, one step back
238)
239240measure(

Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8

lines 241–252why, one step back
241 "immer (es5) - without autofreeze",
242 () => {243 setUseProxies(false)244 setAutoFreeze(false)245 },246 () => {247 produce(baseState, draft => {248 for (let i = 0; i < MAX * MODIFY_FACTOR; i++) {249 draft[i].done = true250 }251 })252 }

docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585

lines 253–255why, one step back
253)
254255measure(

Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8

lines 256–267why, one step back
256 "immer (es5) - with autofreeze",
257 () => {258 setUseProxies(false)259 setAutoFreeze(true)260 },261 () => {262 produce(frozenBazeState, draft => {263 for (let i = 0; i < MAX * MODIFY_FACTOR; i++) {264 draft[i].done = true265 }266 })267 }

docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585

lines 268–270why, one step back
268)
269270measure(

Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8

lines 271–286why, one step back
271 "immer (es5) - without autofreeze - with patch listener",
272 () => {273 setUseProxies(false)274 setAutoFreeze(false)275 },276 () => {277 produce(278 baseState,279 draft => {280 for (let i = 0; i < MAX * MODIFY_FACTOR; i++) {281 draft[i].done = true282 }283 },284 function() {}285 )286 }

docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585

lines 287–289why, one step back
287)
288289measure(

Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8

lines 290–305why, one step back
290 "immer (es5) - with autofreeze - with patch listener",
291 () => {292 setUseProxies(false)293 setAutoFreeze(true)294 },295 () => {296 produce(297 baseState,298 draft => {299 for (let i = 0; i < MAX * MODIFY_FACTOR; i++) {300 draft[i].done = true301 }302 },303 function() {}304 )305 }

docs: fix video player scrolling on chrome, fixes #520Michel Weststratebefore adoptionfbae585

line 306why, one step back
306)