5 ms·
The article states differently, saying it is performant. Instead of saying we should search for benchmarks why not post them here? Also, what is the small fun
by binarymax 3y ago
The article states differently, saying it is performant.
Instead of saying we should search for benchmarks why not post them here? Also, what is the small function you use?
- hutzlibu 3y agoSadly I can confirm, structuredClone is still not performant. At least on my various devices. I just did a test again with 40000 times cloning a simple object and JSON.parse/stringify was 6 times faster than structured cloning. Since I heavily use deep cloning, I am still disappointed with the new native, but slower solution. (And was hoping there would be more than old news in the article) Edit: Code for testing was as simple as for ... 40000 JSON.parse(JSON.stringify(obj)) vs structuredClone(obj)
- meepmorp 3y ago> I just did a test again with 40000 times cloning a simple object and JSON.parse/stringify was 6 times faster than structured cloning. Depending on the object you're cloning, that might be fine. But some types, like Date or Set, don't round trip between JS and JSON so you'd have mangled objects.
- hutzlibu 3y agoYes I know, but 6 times slower is pretty bad, so when someone presents the modern way, he should probably include a warning, that modern not necesarily means better. Because those who used the old way before, know the limits and worked around them. So why should I switch? I wasted time trying it out (not now, when structuredClone came out). Because my assumption was, it should be faster than the JSON abuse. But it is not, it just has more features.