diff options
author | Brian White <mscdex@mscdex.net> | 2015-05-01 14:08:02 -0400 |
---|---|---|
committer | Brian White <mscdex@mscdex.net> | 2015-05-01 21:27:34 -0400 |
commit | c7782c0af8a4e4ee26da6e44e07c3987d9d3ddb6 (patch) | |
tree | c34ab5332254a02afdfa73476c5ce742da981dca /benchmark | |
parent | ea5195ccaf6d51262c9089c2ec5c6f5634bc12b5 (diff) | |
download | android-node-v8-c7782c0af8a4e4ee26da6e44e07c3987d9d3ddb6.tar.gz android-node-v8-c7782c0af8a4e4ee26da6e44e07c3987d9d3ddb6.tar.bz2 android-node-v8-c7782c0af8a4e4ee26da6e44e07c3987d9d3ddb6.zip |
node: improve nextTick performance
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.
PR-URL: https://github.com/iojs/io.js/pull/1571
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
Diffstat (limited to 'benchmark')
-rw-r--r-- | benchmark/misc/next-tick-breadth-args.js | 37 | ||||
-rw-r--r-- | benchmark/misc/next-tick-depth-args.js | 48 |
2 files changed, 85 insertions, 0 deletions
diff --git a/benchmark/misc/next-tick-breadth-args.js b/benchmark/misc/next-tick-breadth-args.js new file mode 100644 index 0000000000..e617fcfc82 --- /dev/null +++ b/benchmark/misc/next-tick-breadth-args.js @@ -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); + } +} diff --git a/benchmark/misc/next-tick-depth-args.js b/benchmark/misc/next-tick-depth-args.js new file mode 100644 index 0000000000..066b483785 --- /dev/null +++ b/benchmark/misc/next-tick-depth-args.js @@ -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); +} |