Perfect your code
With built-in code review tools, GitHub makes it easy to raise the quality bar before you ship. Join the 36 million developers who've merged over 200 million pull requests.
Sign up for free See pricing for teams and enterprisessrc: remove pushValueToArray and setupProcessObject #24264
Conversation
This comment has been minimized.
This comment has been minimized.
nodejs-github-bot
added
C++
lib / src
labels
Nov 9, 2018
This comment has been minimized.
This comment has been minimized.
|
Some local benchmark results:
The Intuitively the new API is doing what has to be done either in JS or C++ - it constructs an Array out of a FixedArray with all the elements readily packed inside, so it shouldn't be slower than the old way (which calls into JS), the impact seems to come from how the new approach affect what gets optimized in a hot loop which rarely happen in real word, so I am inclined to just ignore the results in For reference, something like #24125 shows significant improvement when the length of the array is long enough and the call cannot be optimized (e.g. unconditionally done in C++ land without
|
bmeurer
reviewed
Nov 9, 2018
|
Not sure about the benchmark results TBH. |
| Local<Value> holder = Array::New(isolate); | ||
| Local<Function> fn = env()->push_values_to_array_function(); | ||
| Local<Value> argv[NODE_PUSH_VAL_TO_ARRAY_MAX]; | ||
| std::vector<Local<Value>> origin_v; |
This comment has been minimized.
This comment has been minimized.
bmeurer
Nov 9, 2018
Member
Since you already know the capacity needed for this, how about pre-allocating it here?
This comment has been minimized.
This comment has been minimized.
| fn->Call(env()->context(), headers, j * 2, argv).ToLocalChecked(); | ||
| } | ||
| } while (i < num_values_); | ||
| std::vector<Local<Value>> headers_v; |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
joyeecheung
Nov 11, 2018
Author
Member
Now come to think of it, this one can actually be an array since its capacity cannot be bigger than 32*2, maybe that'll speed it up a bit more..
This comment has been minimized.
This comment has been minimized.
refack
Nov 11, 2018
•
Member
I'd trust Are the benchmark around this? std::vector. No need to over-optimize.
joyeecheung
added some commits
Nov 9, 2018
joyeecheung
force-pushed the
joyeecheung:remove-push
branch
from
3cb8bf9
to
cc511fb
Nov 11, 2018
joyeecheung
added some commits
Nov 9, 2018
joyeecheung
force-pushed the
joyeecheung:remove-push
branch
from
cc511fb
to
db5e5fa
Nov 11, 2018
This comment has been minimized.
This comment has been minimized.
|
Apparently using a fixed-size array in the http parser does the trick, though the impact shown from
when n=100 (somehow accuracy is a little bit better):
Other benchmark results:
|
This comment has been minimized.
This comment has been minimized.
refack
reviewed
Nov 11, 2018
|
|
lib/os.js Outdated
| size_t headers_size = headers.size(); | ||
| std::vector<Local<Value>> headers_v(headers_size * 2); | ||
| for (size_t i = 0; i < headers_size; ++i) { | ||
| nghttp2_header item = headers[i]; |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| } | ||
|
|
||
| Local<Value> holder = Array::New(isolate, origin_v.data(), nov); |
This comment has been minimized.
This comment has been minimized.
refack
reviewed
Nov 11, 2018
refack
reviewed
Nov 11, 2018
This comment was marked as outdated.
This comment was marked as outdated.
I'm still in favor of considering the C++CG as the default, and if we feel the guidelines don't apply, we can always comment and explain why. |
addaleax
approved these changes
Nov 12, 2018
|
Nice work! And, to be explicit, I’m |
| size_t headers_size = headers.size(); | ||
| std::vector<Local<Value>> headers_v(headers_size * 2); | ||
| for (size_t i = 0; i < headers_size; ++i) { | ||
| nghttp2_header item = headers[i]; |
This comment has been minimized.
This comment has been minimized.
| if (j > 0) | ||
| fn->Call(context, holder, j, argv).ToLocalChecked(); | ||
| for (size_t i = 0; i < nov; ++i) { | ||
| auto entry = origin->ov[i]; |
This comment has been minimized.
This comment has been minimized.
addaleax
Nov 12, 2018
Member
I know this is copy-pasted, but I think getting rid of this auto might make things more readable :)
danbev
approved these changes
Nov 13, 2018
joyeecheung
referenced this pull request
Nov 13, 2018
Open
doc: make C++ core guidelines a reference #24315
joyeecheung
added some commits
Nov 11, 2018
This comment has been minimized.
This comment has been minimized.
|
Interesting results: I tried using push_back:
emplace_back:
I suspect RVO is somehow not in effect with the way Fixed a few nits with const references and a few comments. CI: https://ci.nodejs.org/job/node-test-pull-request/18576/ |
joyeecheung
added
the
author ready
label
Nov 13, 2018
joyeecheung
added a commit
that referenced
this pull request
Nov 13, 2018
joyeecheung
added a commit
that referenced
this pull request
Nov 13, 2018
BridgeAR
added a commit
that referenced
this pull request
Nov 14, 2018
BridgeAR
added a commit
that referenced
this pull request
Nov 14, 2018
BridgeAR
added a commit
that referenced
this pull request
Nov 14, 2018
BridgeAR
added a commit
that referenced
this pull request
Nov 14, 2018
BridgeAR
added a commit
that referenced
this pull request
Nov 14, 2018
BridgeAR
added a commit
that referenced
this pull request
Nov 14, 2018
BridgeAR
added a commit
that referenced
this pull request
Nov 14, 2018
BridgeAR
added a commit
that referenced
this pull request
Nov 14, 2018
kiyomizumia
added a commit
to kiyomizumia/node
that referenced
this pull request
Nov 15, 2018
kiyomizumia
added a commit
to kiyomizumia/node
that referenced
this pull request
Nov 15, 2018
kiyomizumia
added a commit
to kiyomizumia/node
that referenced
this pull request
Nov 15, 2018
kiyomizumia
added a commit
to kiyomizumia/node
that referenced
this pull request
Nov 15, 2018
kiyomizumia
added a commit
to kiyomizumia/node
that referenced
this pull request
Nov 15, 2018
kiyomizumia
added a commit
to kiyomizumia/node
that referenced
this pull request
Nov 15, 2018
kiyomizumia
added a commit
to kiyomizumia/node
that referenced
this pull request
Nov 15, 2018
kiyomizumia
added a commit
to kiyomizumia/node
that referenced
this pull request
Nov 15, 2018
This was referenced Nov 15, 2018
This was referenced Nov 17, 2018
This comment has been minimized.
This comment has been minimized.
|
@joyeecheung can/should this be backported to |
joyeecheung commentedNov 9, 2018
This PR removes
pushValueToArrayNODE_PUSH_VAL_TO_ARRAY_MAXenv->env->push_values_to_array_function()In favor of the new V8 C++ API that constructs an Array from a C++ array directly.
Also removes
setupProcessObjectsince by now it is only doing thepush_values_to_array_functionsetup.Also added a test for
os.cpus()values.Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes