Skip to content

Clone: Use structuredClone instead of parse/stringify #6790

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

PTR-inc
Copy link
Contributor

@PTR-inc PTR-inc commented Feb 18, 2025

From node v17 onward there is the function structuredClone to deepcopy an object. Safer and maybe even faster.

@si458 si458 self-assigned this Feb 20, 2025
@si458
Copy link
Collaborator

si458 commented Feb 20, 2025

this post shows its actually slower - nodejs/node#50320

@PTR-inc
Copy link
Contributor Author

PTR-inc commented Feb 22, 2025

Ah interesting! I got my impression from this discussion: what-is-the-most-efficient-way-to-deep-clone-an-object-in-javascript.

The fastness was just my quick interpretation of it being a 1 call versus a 2 call. But the extra complexity of properly cloning a complex object costs cycles, obviously.

The most important aspect was the safety of cloning an object, regardless of the complexity, and it being the 'official' way of properly cloning a object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants