mirror of
https://github.com/nodejs/node.git
synced 2025-05-07 09:52:26 +00:00

Save the setImmediate() callback arguments into an array instead of a closure, and invoke the callback on the arguments from an optimizable function. 60% faster setImmediate with 0 args (15% if self-recursive) 4x faster setImmediate with 1-3 args, 2x with > 3 seems to be faster with less memory pressure when memory is tight Changes: - use L.create() to build faster lists - use runCallback() from within tryOnImmediate() - save the arguments and do not build closures for the callbacks PR-URL: https://github.com/nodejs/node/pull/6436 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
39 lines
949 B
JavaScript
39 lines
949 B
JavaScript
'use strict';
|
|
require('../common');
|
|
var assert = require('assert');
|
|
|
|
let immediateA = false;
|
|
let immediateB = false;
|
|
let immediateC = [];
|
|
let immediateD = [];
|
|
|
|
setImmediate(function() {
|
|
try {
|
|
immediateA = process.hrtime(before);
|
|
} catch (e) {
|
|
console.log('failed to get hrtime with offset');
|
|
}
|
|
clearImmediate(immediateB);
|
|
});
|
|
|
|
const before = process.hrtime();
|
|
|
|
immediateB = setImmediate(function() {
|
|
immediateB = true;
|
|
});
|
|
|
|
setImmediate(function(x, y, z) {
|
|
immediateC = [x, y, z];
|
|
}, 1, 2, 3);
|
|
|
|
setImmediate(function(x, y, z, a, b) {
|
|
immediateD = [x, y, z, a, b];
|
|
}, 1, 2, 3, 4, 5);
|
|
|
|
process.on('exit', function() {
|
|
assert.ok(immediateA, 'Immediate should happen after normal execution');
|
|
assert.notStrictEqual(immediateB, true, 'immediateB should not fire');
|
|
assert.deepStrictEqual(immediateC, [1, 2, 3], 'immediateC args should match');
|
|
assert.deepStrictEqual(immediateD, [1, 2, 3, 4, 5], '5 args should match');
|
|
});
|