Add largeObject and mapNested benchmarks
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Mark Erikson · committed by Mark Erikson · parent e1996ce · Browse files · 1 file·+61 added−1 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+61 added−1 removed
- other:+61 added−1 removed
Provenance
- Commit
e074b51- Tree
4ba836e- Author
Mark Erikson <mark@isquaredsoftware.com>- Committer
Mark Erikson <mark@isquaredsoftware.com>- Parent
e1996ce
1 file changed+61 added−1 removed
modified:perf-testing/immutability-benchmarks.mjs+61 added-1 removed
42 unmodified lines43 id: i,44 name: `name-${i}`,45 isActive: i % 2 === 046 })),47+ largeObject: createLargeObject(BENCHMARK_CONFIG.largeObjectSize),48 api: {49 queries: {},50 provided: {51 keys: {}9 unmodified lines61 const BENCHMARK_CONFIG = {62 iterations: 1,63 arraySize: 100,64 nestedArraySize: 10,65+ largeObjectSize: 1000,66 multiUpdateCount: 5,67 reuseStateIterations: 1068 }69 7 unmodified lines77 // Return a valid ID that exists in the array78 return Math.min(arraySize - 2, Math.max(0, arraySize - 2))79 }80 81+function createLargeObject(size = 100) {82+ const obj = {}83+ for (let i = 0; i < size; i++) {84+ obj[`property${i}`] = {85+ id: i,86+ value: Math.random(),87+ name: `item-${i}`,88+ active: i % 2 === 089+ }90+ }91+ return obj92+}93+94 const add = index => ({95 type: "test/addItem",96 payload: {id: index, value: index, nested: {data: index}}97 })5 unmodified lines103 const update = index => ({104 type: "test/updateItem",105 payload: {id: index, value: index, nestedData: index}106 })107+const updateLargeObject = index => ({108+ type: "test/updateLargeObject",109+ payload: {value: index}110+})111 const concat = index => ({112 type: "test/concatArray",113 payload: Array.from({length: 500}, (_, i) => ({id: i, value: index}))114 })115+const mapNested = () => ({116+ type: "test/mapNested"117+})118 119 const updateHigh = index => ({120 type: "test/updateHighIndex",121 payload: {51 unmodified lines173 add,174 remove,175 filter,176 update,177+ updateLargeObject,178 concat,179+ mapNested,180 // dash-named fields to improve readability in benchmark results181 "update-high": updateHigh,182 "update-multiple": updateMultiple,183 "remove-high": removeHigh,147 unmodified lines331 : item332 )333 }334 }335+ case "test/updateLargeObject": {336+ return {337+ ...state,338+ largeObject: {339+ ...state.largeObject,340+ [`propertyAdded${action.payload.value}`]: {341+ id: action.payload.value342+ }343+ }344+ }345+ }346 case "test/concatArray": {347 const length = state.largeArray.length348 const newArray = action.payload.concat(state.largeArray)349 newArray.length = length1 unmodified line351 ...state,352 largeArray: newArray353 }354 }355+ case "test/mapNested": {356+ // Extract nested data - common pattern for denormalization or view preparation357+ const nestedData = state.largeArray.map(item => item.nested)358+ return {359+ ...state,360+ otherData: nestedData // Store extracted nested objects361+ }362+ }363 case "test/updateHighIndex": {364 return {365 ...state,366 largeArray: state.largeArray.map(item =>94 unmodified lines461 item.value = action.payload.value462 item.nested.data = action.payload.nestedData463 break464 }465+ case "test/updateLargeObject": {466+ draft.largeObject[`propertyAdded${action.payload.value}`] = {467+ id: action.payload.value468+ }469+ break470+ }471 case "test/concatArray": {472 const length = state.largeArray.length473 const newArray = action.payload.concat(state.largeArray)474 newArray.length = length475 draft.largeArray = newArray476 break477 }478+ case "test/mapNested": {479+ // Extract nested data480+ draft.otherData = draft.largeArray.map(item => item.nested)481+ break482+ }483 case "test/updateHighIndex": {484 const item = draft.largeArray.find(485 item => item.id === action.payload.id486 )104 unmodified lines591 })592 }593 594 // State reuse benchmarks (tests performance on frozen/evolved state)541- const reuseActions = ["update", "update-high", "remove", "remove-high"]595+ const reuseActions = [596+ "update",597+ "update-high",598+ "remove",599+ "remove-high",600+ "updateLargeObject"601+ ]602 for (const action of reuseActions) {603 summary(function() {604 bench(`$action-reuse: $version (freeze: $freeze)`, function*(args) {605 const version = args.get("version")676 unmodified lines