Skip to content
Myr

add-data.js

This file

Path

__performance_tests__/add-data.js

115 lines · 2.4 KiB · JavaScript

Last changed by

Optimization: stop recursing if there are no drafts leftMichel Weststratebefore adoptionebda6f8

History of this file

Take it

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

test: extract some tests into their own functionaleclarsonbefore adoption21846ab

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

Fixed performance testsMichel Weststratebefore adoptionc2d7617

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

test: extract some tests into their own functionaleclarsonbefore adoption21846ab

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

Fixed performance testsMichel Weststratebefore adoptionc2d7617

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

test: extract some tests into their own functionaleclarsonbefore adoption21846ab

lines 16–19why, one step back
16console.log("\n# add-data - loading large set of data\n")
1718const dataSet = require("./data.json")19const baseState = {

Fixed performance testsMichel Weststratebefore adoptionc2d7617

line 20why, one step back
20 data: null

test: extract some tests into their own functionaleclarsonbefore adoption21846ab

lines 21–25why, one step back
21}
22const frozenBazeState = deepFreeze(cloneDeep(baseState))23const immutableJsBaseState = fromJS(baseState)24const seamlessBaseState = Seamless.from(baseState)25

Optimization: stop recursing if there are no drafts leftMichel Weststratebefore adoptionebda6f8

lines 26–27why, one step back
26const MAX = 10000
27

test: extract some tests into their own functionaleclarsonbefore adoption21846ab

line 28why, one step back
28measure(

Fixed performance testsMichel Weststratebefore adoptionc2d7617

lines 29–33why, one step back
29 "just mutate",
30 () => ({draft: cloneDeep(baseState)}),31 ({draft}) => {32 draft.data = dataSet33 }

test: extract some tests into their own functionaleclarsonbefore adoption21846ab

lines 34–36why, one step back
34)
3536measure(

Fixed performance testsMichel Weststratebefore adoptionc2d7617

lines 37–42why, one step back
37 "just mutate, freeze",
38 () => ({draft: cloneDeep(baseState)}),39 ({draft}) => {40 draft.data = dataSet41 deepFreeze(draft)42 }

test: extract some tests into their own functionaleclarsonbefore adoption21846ab

lines 43–45why, one step back
43)
4445measure("handcrafted reducer (no freeze)", () => {

Fixed performance testsMichel Weststratebefore adoptionc2d7617

lines 46–49why, one step back
46 const nextState = {
47 ...baseState,48 data: dataSet49 }

test: extract some tests into their own functionaleclarsonbefore adoption21846ab

lines 50–52why, one step back
50})
5152measure("handcrafted reducer (with freeze)", () => {

Fixed performance testsMichel Weststratebefore adoptionc2d7617

lines 53–56why, one step back
53 const nextState = deepFreeze({
54 ...baseState,55 data: dataSet56 })

test: extract some tests into their own functionaleclarsonbefore adoption21846ab

lines 57–59why, one step back
57})
5859measure("immutableJS", () => {

Fixed performance testsMichel Weststratebefore adoptionc2d7617

lines 60–62why, one step back
60 let state = immutableJsBaseState.withMutations(state => {
61 state.setIn(["data"], fromJS(dataSet))62 })

test: extract some tests into their own functionaleclarsonbefore adoption21846ab

lines 63–65why, one step back
63})
6465measure("immutableJS + toJS", () => {

Fixed performance testsMichel Weststratebefore adoptionc2d7617

lines 66–70why, one step back
66 let state = immutableJsBaseState
67 .withMutations(state => {68 state.setIn(["data"], fromJS(dataSet))69 })70 .toJS()

test: extract some tests into their own functionaleclarsonbefore adoption21846ab

lines 71–73why, one step back
71})
7273measure("seamless-immutable", () => {

Fixed performance testsMichel Weststratebefore adoptionc2d7617

line 74why, one step back
74 seamlessBaseState.set("data", dataSet)

test: extract some tests into their own functionaleclarsonbefore adoption21846ab

lines 75–77why, one step back
75})
7677measure("seamless-immutable + asMutable", () => {

Fixed performance testsMichel Weststratebefore adoptionc2d7617

line 78why, one step back
78 seamlessBaseState.set("data", dataSet).asMutable({deep: true})

test: extract some tests into their own functionaleclarsonbefore adoption21846ab

lines 79–80why, one step back
79})
80

Optimization: stop recursing if there are no drafts leftMichel Weststratebefore adoptionebda6f8

line 81why, one step back
81measure("immer (proxy) - without autofreeze * " + MAX, () => {

Fixed performance testsMichel Weststratebefore adoptionc2d7617

lines 82–83why, one step back
82 setUseProxies(true)
83 setAutoFreeze(false)

Optimization: stop recursing if there are no drafts leftMichel Weststratebefore adoptionebda6f8

lines 84–87why, one step back
84 for (let i = 0; i < MAX; i++)
85 produce(baseState, draft => {86 draft.data = dataSet87 })

test: extract some tests into their own functionaleclarsonbefore adoption21846ab

lines 88–89why, one step back
88})
89

Optimization: stop recursing if there are no drafts leftMichel Weststratebefore adoptionebda6f8

line 90why, one step back
90measure("immer (proxy) - with autofreeze * " + MAX, () => {

Fixed performance testsMichel Weststratebefore adoptionc2d7617

lines 91–92why, one step back
91 setUseProxies(true)
92 setAutoFreeze(true)

Optimization: stop recursing if there are no drafts leftMichel Weststratebefore adoptionebda6f8

lines 93–96why, one step back
93 for (let i = 0; i < MAX; i++)
94 produce(frozenBazeState, draft => {95 draft.data = dataSet96 })

test: extract some tests into their own functionaleclarsonbefore adoption21846ab

lines 97–98why, one step back
97})
98

Optimization: stop recursing if there are no drafts leftMichel Weststratebefore adoptionebda6f8

line 99why, one step back
99measure("immer (es5) - without autofreeze * " + MAX, () => {

Fixed performance testsMichel Weststratebefore adoptionc2d7617

lines 100–101why, one step back
100 setUseProxies(false)
101 setAutoFreeze(false)

Optimization: stop recursing if there are no drafts leftMichel Weststratebefore adoptionebda6f8

lines 102–105why, one step back
102 for (let i = 0; i < MAX; i++)
103 produce(baseState, draft => {104 draft.data = dataSet105 })

test: extract some tests into their own functionaleclarsonbefore adoption21846ab

lines 106–107why, one step back
106})
107

Optimization: stop recursing if there are no drafts leftMichel Weststratebefore adoptionebda6f8

line 108why, one step back
108measure("immer (es5) - with autofreeze * " + MAX, () => {

Fixed performance testsMichel Weststratebefore adoptionc2d7617

lines 109–110why, one step back
109 setUseProxies(false)
110 setAutoFreeze(true)

Optimization: stop recursing if there are no drafts leftMichel Weststratebefore adoptionebda6f8

lines 111–114why, one step back
111 for (let i = 0; i < MAX; i++)
112 produce(frozenBazeState, draft => {113 draft.data = dataSet114 })

test: extract some tests into their own functionaleclarsonbefore adoption21846ab

line 115why, one step back
115})