-
Notifications
You must be signed in to change notification settings - Fork 30.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
os: improve cpus() performance #11564
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with a suggestion.
src/node_os.cc
Outdated
fields[4] = ci->cpu_times.idle; | ||
fields[5] = ci->cpu_times.irq; | ||
Local<Value> argv[] = { | ||
OneByteString(env->isolate(), ci->model) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another possible enhancement: cache the result and check on the next iteration:
Local<String> model_string;
int model_index;
// Then inside the loop...
if (model_string.IsEmpty() ||
0 != strcmp(ci->model, cpu_infos[model_index).model) {
model_string = OneByteString(env->isolate(), ci->model);
model_index = i;
}
Local<Value> argv[] = { model_string };
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just tried that in addition to the changes I just made and did not see any difference.
I've now tweaked the code to squeeze out a bit more speed. |
LGTM |
env->context(), | ||
OneByteString(env->isolate(), "pushValToArrayMax"), | ||
Integer::NewFromUnsigned(env->isolate(), NODE_PUSH_VAL_TO_ARRAY_MAX), | ||
v8::ReadOnly).FromJust(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume the old PropertyAttribute
-based API is used rather than the ES5 PropertyDescriptor
-based one for ease of backporting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just copied from the READONLY_PROPERTY
macro in src/node.cc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could leave out the ReadOnly flag entirely since it's only a bindings object property.
env->context(), | ||
OneByteString(env->isolate(), "pushValToArrayMax"), | ||
Integer::NewFromUnsigned(env->isolate(), NODE_PUSH_VAL_TO_ARRAY_MAX), | ||
v8::ReadOnly).FromJust(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could leave out the ReadOnly flag entirely since it's only a bindings object property.
@mscdex looks like every test failed on AIX (there were also SmartOS failures, but I'm not sure what caused them).
I suspect this was caused by the |
Alright, after duplicating the issue on a smartos16-64 CI node (base-64 16.2.0), the crash appears to be happening in V8, not in node's code. I did a
The example test I used to trigger this was test/parallel/test-async-wrap-check-providers.js. /cc @nodejs/v8 ? |
Does it also crash with cc @nodejs/platform-smartos because it happens in libumem. |
@bnoordhuis With that flag it still crashes. This time the backtrace is:
|
False alarm, it was just a bug in the code I added. It only appeared on the SmartOS and AIX CI machines because they had a large enough CPU count to trigger the bug. New CI: https://ci.nodejs.org/job/node-test-pull-request/6653/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with a suggestion.
src/node_os.cc
Outdated
if (model_idx >= NODE_PUSH_VAL_TO_ARRAY_MAX) { | ||
addfn->Call(env->context(), cpus, model_idx, model_argv).ToLocalChecked(); | ||
model_idx = 0; | ||
f = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Call this field_idx
maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed.
CI is green except for unrelated test failures. Hooray! |
Rerun of CI was even more green! |
PR-URL: nodejs#11564 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jackson Tian <shyvo1987@gmail.com>
PR-URL: #11564 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jackson Tian <shyvo1987@gmail.com>
@mscdex thoughts on backport? |
Results with included benchmark:
CI: https://ci.nodejs.org/job/node-test-pull-request/6591/
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)