Urgent.News

What's breaking now, across hundreds of outlets.

Tech

structuredClone vs JSON.stringify: I Timed Both on Node 22

On Node 22, JSON.parse(JSON.stringify()) cloned objects 1.6 to 1.75 times faster than structuredClone across three sizes structuredClone handles Dates, Maps and circular references that the JSON method silently breaks or drops I benchmarked 20000, 2000 and 200 clone operations at three object depths, same count each run The JSON method still loses functions and undefined, so the speed win comes…

The comparison of structuredClone and JSON.stringify deep cloning methods in Node 22 reveals that the JSON method significantly outperforms structuredClone. Across three object sizes ranging from small to large, structuredClone was 1.6 to 1.75 times slower than JSON.stringify. This speed advantage comes at the cost of losing certain data types, such as functions and undefined values, which JSON.stringify also handles.

The benchmark script tested the performance of both methods with varying object depths and sizes, ensuring accurate results by checking for equal output shapes and avoiding potential GC pauses or CPU throttling glitches. The consistent results across multiple runs and object sizes prove that this speed gap is real and not an artifact of the specific script execution.

The results indicate that the choice between the two methods should depend on the specific use case and the trade-offs one is willing to make between performance and data fidelity.

Rewritten by urgent.news; may contain errors — check the original.

Read the original at dev.to →

Report a problem with this story

More in Tech

How to stop forgetting to reply to messages (habits + WhatsApp and Gmail settings)

You read it. You thought, "I'll answer properly later." Three days later the person writes again – "Did you see my message?" – and you feel terrible.

  • Use the "two-minute rule" for quick replies or mark for later
  • Batch process replies during set times throughout the day
  • Utilize templates, voice messages, and reminders to streamline responses

Debugging Without Guessing: A Practical Method for Finding the Real Problem

Every developer eventually runs into a bug that seems to make no sense. The page is blank, even though the component looks fine. A function works with one input and fails with another.

  • Clearly define the bug with specific expected and actual outcomes
  • Reproduce the issue consistently to gather reliable evidence
  • Analyze error messages for clues about the bug's origin

More from Saturday 21 November →