codeandcats / fast-clone Goto Github PK
View Code? Open in Web Editor NEWExtremely fast javascript deep cloning function
License: MIT License
Extremely fast javascript deep cloning function
License: MIT License
It's 2018 and this library doesn't have typings!
Would be nice to rewrite in TypeScript and just publish the generated .js
and .d.ts
files.
Dependabot was recently acquired by Github, has the same features and more so makes sense.
So you could for example, exclude all the properties starting with $ from being cloned.
Angular likes to attach extra '$...' properties to scoped objects, and although there exists angular.copy
for cloning objects without the $ props, fast-clone is faster and can be used both on server and client. So would be handy to have.
To run the benchmarks I had to lock jsdom
to npm install -D [email protected]
because benv
doesn't specify a version range, and the new jsdom
has deprecated methods that were being used by benv
.
Anyways, the benchmarks consistently showed rfdc
as the fastest approach.
λ ~/Projects/fast-clone/ master* npm run benchmark
> [email protected] benchmark /Users/jack/Projects/fast-clone
> ts-node --files ./support/benchmark
Generating random json data...
Done.
Test data size is: 7.15 MB
Running benchmark 1 of 7... Done
Running benchmark 2 of 7... Done
Running benchmark 3 of 7... Done
Running benchmark 4 of 7... Done
Running benchmark 5 of 7... Done
Running benchmark 6 of 7... Done
Running benchmark 7 of 7... Done
Library | Time
-----------------|---------
clone | 2,181 ms
angular.copy | 1,715 ms
snapshot | 1,182 ms
lodash.cloneDeep | 197 ms
fast-clone | 149 ms
deepClone | 139 ms
rfdc | 35 ms
How does this function perform in comparison with JSON.parse(JSON.stringify(obj))
?
This library does not support circular references, but if we could still get the same performance while supporting them it would be great! An alternative would be to add an option to enable it, so that existing users won't be affected and still get the same super-fast cloning.
For handling specific types/paths in the tree, so if there is a particular object for example that you need to create with a specific constructor then you can.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.