Uh oh!
There was an error while loading. Please reload this page.
node: improve GetActiveRequests performance - #3375
Conversation
rvagg
commented
Oct 15, 2015
Is "index" the right word to use here? you're just appending and not actually using an index |
ronkorving
commented
Oct 15, 2015
While performance improvements are nice, this definitely adds more code than it removes. Is the use case here continuous monitoring? This is still an undocumented API... for what reason I don't know though, seems it would help to make it public (I've used it too, and find it very useful, but that's usually been limited to shutdown-time). |
trevnorris
commented
Oct 15, 2015
@rvagg That's an artifact of an early implementation. I'll find a better name. @ronkorving The use case is to not have a crappy implementation. This is a technique that I plan to expand through core. Search for LOC should have little to no affect on a PR. Added complexity I can understand, and can agree with based on circumstance. This though is fairly straightforward. |
ronkorving
commented
Oct 16, 2015
Is there any way we could help the V8 team (I say we.. as if I really could) to make Object::Set as fast as JIT compiled JavaScript? |
There was a problem hiding this comment.
Can you use ARRAY_SIZE(argv) instead of hard-coding it in several places? If it gets unwieldy, I suggest writing it as:
static const size_t argc = 5;
Local<Value> argv[argc];
// ...
argv[i++ % argc] = ...;
bnoordhuis
commented
Oct 17, 2015
This could be extended to numerous other places but I assume that's your plan anyway. :-) |
1d1139e to
1e42a7fComparetrevnorris
commented
Oct 19, 2015
@bnoordhuis Comments addressed (I think). Yes, I am planning on extending this across core but figured this would be a good low impact place to start off. :) |
There was a problem hiding this comment.
Shouldn't this check that i > 0? It's going to make a superfluous JS call now if I read it right.
EDIT: Never mind, didn't read it right. It's never zero.
There was a problem hiding this comment.
this is the most succinct way I found, but even looking back at this over the weekend I needed to remember what the logic was doing. if you have something more readable in mind I'm open to suggestions. :)
1e42a7f to
2c6de7aComparetrevnorris
commented
Oct 19, 2015
@bnoordhuis made most suggested changes and added a simple test. |
There was a problem hiding this comment.
This is the repetition I mean. I'd do the i % argc only once and cache the result in a const size_t remainder.
There was a problem hiding this comment.
ah, got it. was trying to make it work w/ the for loop above.
2c6de7a to
7daff51Comparetrevnorris
commented
Oct 21, 2015
@bnoordhuis comment addressed. |
jasnell
commented
Oct 21, 2015
Nice change, although it makes me sad that Object::Set is so slow. LGTM so long as CI is green and |
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: 690 ns/op 5.4x faster7daff51 to
d1dd435Comparetrevnorris
commented
Oct 21, 2015
@bnoordhuis@jasnell |
jasnell
commented
Oct 21, 2015
LGTM if CI is green |
bnoordhuis
commented
Oct 21, 2015
LGTM |
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: 690 ns/op 5.4x faster
PR-URL: #3375
Reviewed-By: James Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <ben@strongloop.com>trevnorris
commented
Oct 21, 2015
None of the failures are related to the PR. Landed on 494227b. Thanks much! |
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: 690 ns/op 5.4x faster
PR-URL: #3375
Reviewed-By: James Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <ben@strongloop.com>MylesBorins
commented
Mar 11, 2016
@trevnorris what are your thought regarding adding this commit to LTS? |
MylesBorins
commented
Apr 11, 2016
@trevnorris ping |
trevnorris
commented
Apr 11, 2016
@thealphanerd oop. sorry. It's a micro-performance optimization. Merging will doubtfully prevent future conflicts. So, can land but don't think it's necessary. |
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:
Results between the two:
R=@bnoordhuis
Have another addition of improving the same for active handles, but wanted to solicit feedback on the approach early.