From d1549bf8d94bd788ab5d06aadd0087c3c23d9ed3 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Fri, 3 Feb 2017 12:46:23 +0100 Subject: [PATCH] lib: add constant kMaxCallbacksUntilQueueIsShortened Currently the maximum number of tick is duplicated in two places. This commit introduces a constant that both can use. PR-URL: https://github.com/nodejs/node/pull/11199 Reviewed-By: Anna Henningsen Reviewed-By: Ben Noordhuis Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Trevor Norris --- lib/internal/process/next_tick.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/internal/process/next_tick.js b/lib/internal/process/next_tick.js index f27ef622a96e6a..bc89c6e8b269e3 100644 --- a/lib/internal/process/next_tick.js +++ b/lib/internal/process/next_tick.js @@ -1,5 +1,11 @@ 'use strict'; +// This value is used to prevent the nextTickQueue from becoming too +// large and cause the process to run out of memory. When this value +// is reached the nextTimeQueue array will be shortend (see tickDone +// for details). +const kMaxCallbacksUntilQueueIsShortened = 1e4; + exports.setup = setupNextTick; function setupNextTick() { @@ -96,7 +102,7 @@ function setupNextTick() { // callback invocation with small numbers of arguments to avoid the // performance hit associated with using `fn.apply()` _combinedTickCallback(args, callback); - if (1e4 < tickInfo[kIndex]) + if (kMaxCallbacksUntilQueueIsShortened < tickInfo[kIndex]) tickDone(); } tickDone(); @@ -120,7 +126,7 @@ function setupNextTick() { // callback invocation with small numbers of arguments to avoid the // performance hit associated with using `fn.apply()` _combinedTickCallback(args, callback); - if (1e4 < tickInfo[kIndex]) + if (kMaxCallbacksUntilQueueIsShortened < tickInfo[kIndex]) tickDone(); if (domain) domain.exit();