-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit uses separate functions to isolate deopts caused by try-catches and avoids fn.apply() for callbacks with small numbers of arguments. These changes improve performance by ~1-40% in the various nextTick benchmarks.
- Loading branch information
Showing
5 changed files
with
189 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
'use strict'; | ||
|
||
var common = require('../common.js'); | ||
var bench = common.createBenchmark(main, { | ||
millions: [2] | ||
}); | ||
|
||
function main(conf) { | ||
var N = +conf.millions * 1e6; | ||
var n = 0; | ||
|
||
function cb1(arg1) { | ||
n++; | ||
if (n === N) | ||
bench.end(n / 1e6); | ||
} | ||
function cb2(arg1, arg2) { | ||
n++; | ||
if (n === N) | ||
bench.end(n / 1e6); | ||
} | ||
function cb3(arg1, arg2, arg3) { | ||
n++; | ||
if (n === N) | ||
bench.end(n / 1e6); | ||
} | ||
|
||
bench.start(); | ||
for (var i = 0; i < N; i++) { | ||
if (i % 3 === 0) | ||
process.nextTick(cb3, 512, true, null); | ||
else if (i % 2 === 0) | ||
process.nextTick(cb2, false, 5.1); | ||
else | ||
process.nextTick(cb1, 0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
'use strict'; | ||
|
||
var common = require('../common.js'); | ||
var bench = common.createBenchmark(main, { | ||
millions: [2] | ||
}); | ||
|
||
process.maxTickDepth = Infinity; | ||
|
||
function main(conf) { | ||
var n = +conf.millions * 1e6; | ||
|
||
function cb3(arg1, arg2, arg3) { | ||
if (--n) { | ||
if (n % 3 === 0) | ||
process.nextTick(cb3, 512, true, null); | ||
else if (n % 2 === 0) | ||
process.nextTick(cb2, false, 5.1); | ||
else | ||
process.nextTick(cb1, 0); | ||
} else | ||
bench.end(+conf.millions); | ||
} | ||
function cb2(arg1, arg2) { | ||
if (--n) { | ||
if (n % 3 === 0) | ||
process.nextTick(cb3, 512, true, null); | ||
else if (n % 2 === 0) | ||
process.nextTick(cb2, false, 5.1); | ||
else | ||
process.nextTick(cb1, 0); | ||
} else | ||
bench.end(+conf.millions); | ||
} | ||
function cb1(arg1) { | ||
if (--n) { | ||
if (n % 3 === 0) | ||
process.nextTick(cb3, 512, true, null); | ||
else if (n % 2 === 0) | ||
process.nextTick(cb2, false, 5.1); | ||
else | ||
process.nextTick(cb1, 0); | ||
} else | ||
bench.end(+conf.millions); | ||
} | ||
bench.start(); | ||
process.nextTick(cb1, true); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters