Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save creationix/539223 to your computer and use it in GitHub Desktop.
Save creationix/539223 to your computer and use it in GitHub Desktop.
From 40254b255250d5b889699eb655c8d30c00d322a3 Mon Sep 17 00:00:00 2001
From: Tim Caswell <tim@creationix.com>
Date: Thu, 19 Aug 2010 18:58:28 -0700
Subject: [PATCH] Make process.nextTick worlds faster for large queues.
---
src/node.js | 7 +++++--
1 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/node.js b/src/node.js
index d38f12d..82a5937 100644
--- a/src/node.js
+++ b/src/node.js
@@ -47,9 +47,12 @@ process.evalcx = function () {
var nextTickQueue = [];
process._tickCallback = function () {
- for (var l = nextTickQueue.length; l; l--) {
- nextTickQueue.shift()();
+ var l = nextTickQueue.length;
+ if (l === 0) return;
+ for (var i = 0; i < l; i++) {
+ nextTickQueue[i]();
}
+ nextTickQueue.splice(0, l);
};
process.nextTick = function (callback) {
--
1.7.2
@TooTallNate
Copy link

You think this would be any faster?

var l = nextTickQueue.length, i = 0;
if (l === 0) return;
while (i < l) {
  nextTickQueue[i++]();
}

@tj
Copy link

tj commented Aug 20, 2010

not by much no, over optimization

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