question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

R.clone is really slow

See original GitHub issue

R.clone is quite slow. I process 1000 invoices; each invoice has 5 lineItems on average, So I am running R.clone 5000 times. The documentation should have some kind of warning, under which circumstances it is slow.

function PackingList ( invoice ) {
    var packingList = invoice.LineItems;
    packingList = R.filter ( lineItem => !invoiceCost.IsNotShippable(lineItem), packingList );
    packingList = R.filter ( lineItem => (lineItem.ProductFound===true ), packingList );
    packingList = packingList.map ( lineItem => R.clone (lineItem) ); // we will modify the quantities, therefore we need to clone$
    R.map ( lineItem => lineItem.Quantity = parseFloat (lineItem.Quantity), packingList);
    R.map ( lineItem => lineItem.ProductWeight = lineItem.Weight /  lineItem.Quantity , packingList);
    return packingList;
}

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:25 (12 by maintainers)

github_iconTop GitHub Comments

5reactions
CrossEyecommented, Apr 4, 2017

@Fi3: If you want only a shallow clone, then you can use merge({}).

clone(obj);  // takes ~650ms on an ancient machine

merge({}, obj); // takes ~5ms on that machine
3reactions
danilloslcommented, Feb 17, 2020

I just made a pool request with a modified _clone function 2985, with this modification the ramda.clone() goes from 93.228ms to 6.829ms on average after 100 iterations cloning this object.

comparison between ramda lodash and JSON.parse(JSON.stringify(obj)) before:

max/min/avg time in ms after 100 runs ramda clone(): max: 124.229 min: 90.160 avg: 93.228 lodash cloneDeep(): max: 26.819 min: 10.101 avg: 11.643 JSON.parse(JSON.stringify(obj)): max: 17.482 min: 9.535 avg: 10.851

and after :

max/min/avg time in ms after 100 runs ramda clone(): max: 35.512 min: 4.916 avg: 6.829 lodash cloneDeep(): max: 26.919 min: 9.832 avg: 10.937 JSON.parse(JSON.stringify(obj)): max: 19.063 min: 9.525 avg: 10.542

Read more comments on GitHub >

github_iconTop Results From Across the Web

Very slow moving and copying files Windows - rclone forum
What is the problem you are having with rclone? Gdrive mounted in network mode but also tried folder mode, copying to the desktop...
Read more >
very slow : r/rclone - Reddit
very slow. quick question. I recently set up rclone which is great and very handy to link to my onedrive. However, in the...
Read more >
T134232 ToolLabs git clone is really slow
A trick that you can use to speed up cloning is to make your initial clones on a host-local filesystem (like /tmp) and...
Read more >
Rsync with hard links very slow compared to rclone - Super User
Inside the docker a sftp-folder is mounted using sshfs. I always used rclone to sync the files: rclone sync --create-empty-src-dirs -v /mnt/sftp ...
Read more >
rclone slow transfer from bucket to filesystem - Stack Overflow
Maybe the CPU is the bottleneck? As encoding and decoding stuff takes quite a lot of computing power. Try top when a copy...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found