{"ScriptPreparationCode":"function deepFreeze(obj) {\r\n const stack = [obj];\r\n const visited = new WeakSet();\r\n \r\n while (stack.length \u003E 0) {\r\n const current = stack.pop();\r\n \r\n if (visited.has(current)) continue;\r\n visited.add(current);\r\n \r\n Object.freeze(current);\r\n \r\n for (const key of Reflect.ownKeys(current)) {\r\n const value = current[key];\r\n if (\r\n value !== null \u0026\u0026\r\n (typeof value === \u0022object\u0022 || typeof value === \u0022function\u0022) \u0026\u0026\r\n !Object.isFrozen(value)\r\n ) {\r\n stack.push(value);\r\n }\r\n }\r\n }\r\n \r\n return obj;\r\n}\r\n\r\nfunction deepFreeze2(object) {\r\n // Retrieve the property names defined on object\r\n const propNames = Reflect.ownKeys(object);\r\n\r\n // Freeze properties before freezing self\r\n for (const name of propNames) {\r\n const value = object[name];\r\n\r\n if ((value \u0026\u0026 typeof value === \u0022object\u0022) || typeof value === \u0022function\u0022) {\r\n deepFreeze(value);\r\n }\r\n }\r\n\r\n return Object.freeze(object);\r\n}\r\n\r\nfunction cowFreeze(obj) {\r\n return new Proxy(obj, {\r\n set(target, prop, value) {\r\n throw new Error(\u0022Immutable: cannot modify frozen object\u0022);\r\n },\r\n get(target, prop) {\r\n const val = target[prop];\r\n if (val \u0026\u0026 typeof val === \u0022object\u0022) {\r\n return cowFreeze(val); // lazily wrap nested objects\r\n }\r\n return val;\r\n }\r\n });\r\n}\r\n\r\n// Large fake object manufacturer\r\nfunction createMockData({ depth = 4, breadth = 6, includeCycles = true, crossLinkRatio = 0.02 } = {}) {\r\n // nodes list to optionally create cross-links\r\n const nodes = [];\r\n \r\n function makeNode(level, path) {\r\n const node = { __id: path.join(\u0027.\u0027) };\r\n nodes.push(node);\r\n \r\n // add many primitive props to increase size\r\n for (let i = 0; i \u003C Math.min(8, breadth); i\u002B\u002B) {\r\n node[\u0027p\u0027 \u002B i] = \u0060val-${path.join(\u0027-\u0027)}-${i}\u0060;\r\n }\r\n \r\n // add symbol keys occasionally\r\n if (level % 2 === 0) {\r\n const s = Symbol(\u0027sym\u0027 \u002B path.join(\u0027-\u0027));\r\n node[s] = \u0060symval-${path.join(\u0027-\u0027)}\u0060;\r\n }\r\n \r\n if (level \u003C depth) {\r\n node.children = [];\r\n for (let b = 0; b \u003C breadth; b\u002B\u002B) {\r\n const child = makeNode(level \u002B 1, path.concat(b));\r\n node.children.push(child);\r\n }\r\n } else {\r\n // leaf: add a large array to increase memory footprint\r\n node.leafArray = new Array(Math.min(200, breadth * 20)).fill(0).map((_, i) =\u003E \u0060${path.join(\u0027-\u0027)}-item-${i}\u0060);\r\n }\r\n \r\n return node;\r\n }\r\n \r\n const root = makeNode(0, [\u0027root\u0027]);\r\n \r\n if (includeCycles) {\r\n // add some self-loops and cross-links\r\n for (let i = 0; i \u003C Math.max(1, Math.floor(nodes.length * 0.005)); i\u002B\u002B) {\r\n const idx = Math.floor(Math.random() * nodes.length);\r\n nodes[idx].self = nodes[idx]; // self-loop\r\n }\r\n \r\n // cross links based on ratio\r\n const crossCount = Math.floor(nodes.length * crossLinkRatio);\r\n for (let i = 0; i \u003C crossCount; i\u002B\u002B) {\r\n const a = nodes[Math.floor(Math.random() * nodes.length)];\r\n const b = nodes[Math.floor(Math.random() * nodes.length)];\r\n if (a \u0026\u0026 b \u0026\u0026 a !== b) {\r\n // attach a cross reference\r\n (a.crossRefs || (a.crossRefs = [])).push(b);\r\n }\r\n }\r\n \r\n // optional parent references using WeakMap style external map\r\n // (not attached to objects to avoid extra cycles unless desired)\r\n }\r\n \r\n return { root, _meta: { createdAt: Date.now(), nodeCount: nodes.length } };\r\n}\r\n\r\nconst small = createMockData({ depth: 1, breadth: 2, includeCycles: false });\r\nconst big = createMockData(({ depth: 2, breadth: 3, includeCycles: true, crossLinkRatio: 0.005 }));\r\n","TestCases":[{"Name":"(Small Object) Stack \u002B WeakSet Cycle Detection","Code":"deepFreeze(structuredClone(small));","IsDeferred":false},{"Name":"(Small Object) Recursively Freeze","Code":"deepFreeze2(structuredClone(small));","IsDeferred":false},{"Name":"(Small Object) Copy-on-write","Code":"cowFreeze(structuredClone(small));","IsDeferred":false},{"Name":"(Big Object) Stack \u002B WeakSet Cycle Detection","Code":"deepFreeze(structuredClone(big));","IsDeferred":false},{"Name":"(Big Object) Recursively Freeze","Code":"deepFreeze2(structuredClone(big));","IsDeferred":false},{"Name":"(Big Object) Proxy copy-on-write","Code":"cowFreeze(structuredClone(big));","IsDeferred":false}]}