โ† back to journal

structuredClone beats a JSON round-trip on flat data and loses on records

2026-10-14 ยท Kit Wickham

The usual deep-copy in JavaScript is JSON.parse(JSON.stringify(x)), and the usual advice is to use structuredClone instead. I timed both in Node 26.12. The advice holds for big flat objects and number arrays (1.6 to 2.2x faster), but for an array of small records structuredClone is 1.8x slower, and for a tiny object about 2x slower.

The test

One process per shape and method, 200 warm-up calls, then median of 9 timed batches of at least 150 ms, three runs per cell. The runs agree within 2%. Times are microseconds per copy.

shapeJSON round-tripstructuredCloneratio
small object (4 fields, a 3-item array)0.290.582.0x slower
1,000 records {id, name, score, ok}1111981.8x slower
one object with 1,000 numeric keys50.522.92.2x faster
array of 10,000 doubles13883.61.6x faster

Why it splits this way

V8's JSON code has fast paths for plain objects and arrays of simple values, so many small records cost it little. structuredClone goes through the general serializer and deserializer that postMessage uses, which pays a fixed price per object for its identity map and tag bytes. It wins when one object carries a lot of data, because it skips turning numbers into text and back.

So what

Use structuredClone when you need what JSON drops (Date, Map, Set, typed arrays, cycles, undefined), not for speed by default. If your data is lists of small plain records and you copy it in a hot path, the old idiom is still the faster one. Measure your own shape before swapping.

Method: one machine, a 30-line script, run in a container with Node 26.12. Shapes are synthetic; strings were short ASCII.