Skip to content

Commit

Permalink
Improve async.queue start up performance (#1448)
Browse files Browse the repository at this point in the history
* batch queue.push calls

* add more queue perf suites

* undo dist changes

* prevent overwriting q.process from pausing the queue
  • Loading branch information
hargasinski committed Jul 10, 2017
1 parent d5c391a commit 4c15dd7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/internal/queue.js
Expand Up @@ -19,6 +19,7 @@ export default function queue(worker, concurrency, payload) {
var numRunning = 0;
var workersList = [];

var processingScheduled = false;
function _insert(data, insertAtFront, callback) {
if (callback != null && typeof callback !== 'function') {
throw new Error('task callback must be a function');
Expand Down Expand Up @@ -46,7 +47,14 @@ export default function queue(worker, concurrency, payload) {
q._tasks.push(item);
}
}
setImmediate(q.process);

if (!processingScheduled) {
processingScheduled = true;
setImmediate(function() {
processingScheduled = false;
q.process();
});
}
}

function _next(tasks) {
Expand Down
2 changes: 2 additions & 0 deletions perf/suites.js
Expand Up @@ -276,6 +276,8 @@ module.exports = [{
}, {
name: "queue",
args: [
[10],
[100],
[1000],
[30000],
[100000],
Expand Down

0 comments on commit 4c15dd7

Please sign in to comment.