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

cloneDeep performance #1984

Closed
elado opened this Issue Feb 11, 2016 · 3 comments

Comments

3 participants
@elado
Copy link

elado commented Feb 11, 2016

Compared to other clone packages or a simple JSON.parse(JSON.stringify(o)), _.cloneDeep is extremely slow. While JSON isn't always a good fit (e.g. when copying a function) it's still faster.

Is there anything _.cloneDeep is doing that the other implementation doesn't?

@jdalton jdalton added the question label Feb 11, 2016

@jdalton

This comment has been minimized.

Copy link
Member

jdalton commented Feb 11, 2016

Hi @elado!

Our deep clone perf compared to others or JSON will be slower. Ours tackles array buffers, buffers, dates, maps, nulls, regexes, sets, symbols, typed arrays, boolean/number/string objects, and circular references. If you know the data you're going to clone is JSON compatible then go for it. However, knowing if your data is JSON compatible isn't always straight forward
(See npm/pull/11306).

I'd like to avoid explicitly calling out perf. We already cover the things cloneDeep does and that it's recursive which is a good indicator.

@jdalton jdalton closed this Feb 11, 2016

@runvnc

This comment has been minimized.

Copy link

runvnc commented Dec 17, 2016

I think you should call out performance explicitly while at the same time mentioning that other cloning modules may not handle all of the cases you do.

cloneDeep performance issues have become the biggest slowdown in my current application so I will have to find another module. The reason I had used this clone rather than other modules, and also had not considered it was giving a problem was because of the reputation of lodash.

@jdalton

This comment has been minimized.

Copy link
Member

jdalton commented Dec 17, 2016

@runvnc

cloneDeep performance issues have become the biggest slowdown in my current application so I will have to find another module.

Use the tool that's best for your situation. If a generic recursive clone with circular reference guards doesn't fit your needs, then by all means use another clone that does.

@lodash lodash locked and limited conversation to collaborators Dec 17, 2016

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.