From ec8b7d3e62e8f4d07997ab171d745ec81f57926d Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Tue, 9 Jun 2015 18:13:13 +0200 Subject: [PATCH] lib: fix expensive isNaN call in readable streams Replace a call to `isNaN(n)` with `n !== n`. Removes most of the overhead from the following hotspot: 13.59% iojs perf-603.map [.] LazyCompile:*isNaN native v8natives.js:67 --- lib/_stream_readable.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js index bebbc80e2bf8dc..804b46e1f47d8d 100644 --- a/lib/_stream_readable.js +++ b/lib/_stream_readable.js @@ -211,7 +211,7 @@ function howMuchToRead(n, state) { if (state.objectMode) return n === 0 ? 0 : 1; - if (n === null || isNaN(n)) { + if (n === null || n !== n) { // only flow one buffer at a time if (state.flowing && state.buffer.length) return state.buffer[0].length;