Skip to content

node: improve GetActiveRequests performance

v8 is faster at setting object properties in JS than C++. Even when it requires calling into JS from native code. Make process._getActiveRequests() faster by doing this when populating the array containing request objects.

Simple benchmark:

for (let i = 0; i < 22; i++)
  fs.open(__filename, 'r', function() { });
let t = process.hrtime();
for (let i = 0; i < 1e6; i++)
  process._getActiveRequests();
t = process.hrtime(t);
console.log((t[0] * 1e9 + t[1]) / 1e6);

Results between the two:

Previous:  4406 ns/op
Patched:    829 ns/op     4.3x faster

R=@bnoordhuis

Have another addition of improving the same for active handles, but wanted to solicit feedback on the approach early.

Merge request reports

Loading