co-parallel icon indicating copy to clipboard operation
co-parallel copied to clipboard

Document why this is better than yield array

Open fzaninotto opened this issue 11 years ago • 5 comments

Why is co-parallel better than simply yielding an array within co? I can't find any documentation about that, and my tests don't show any particular advantage:

// tasks is an array of 200 async tasks simulated by setTimeout, cf #3
var start = Date.now();
yield parallel(tasks, 10);
console.log('total used %dms', Date.now() - start);

This takes 170ms on average, while:

// tasks is an array of 200 async tasks simulated by setTimeout, cf #3
var start = Date.now();
yield tasks;
console.log('total used %dms', Date.now() - start);

This takes 117ms on average

fzaninotto avatar Nov 13 '14 15:11 fzaninotto

by limiting the maximum concurrency you can control both cpu and memory usage of the task

juliangruber avatar Nov 13 '14 15:11 juliangruber

OK, so parallel is supposed to be slower than yield array by design, is that so?

fzaninotto avatar Nov 13 '14 16:11 fzaninotto

co-parallel will be faster when the array you yield is too big so the node proc would reach its limits, and it will help to ensure not too many sockets are open at once etc.

juliangruber avatar Nov 14 '14 08:11 juliangruber

what I don't like about this is that we have N * Array.length functions to allocate instead of having a better co-each, am I correct?

kilianc avatar Jun 09 '15 03:06 kilianc

just to be more precise: yield* parallel(list, action, max)

kilianc avatar Jun 09 '15 04:06 kilianc