-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
http: use direct parameters instead #10833
Conversation
}; | ||
|
||
ClientRequest.prototype.setSocketKeepAlive = _setSocketKeepAlive; |
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 think the underscore should be removed here, so that the function name matches the prototype property name, just like with setNoDelay()
above.
Nit: saying the arguments were being leaked is a bit misleading, it makes it sound as if the |
caculate([noDelay]); | ||
} | ||
|
||
var common = require('../common.js'); |
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.
This should go at the top of the file, after 'use strict';
. I would probably also put the var bench = ...
after this var common = ...
line at the top as well.
Basically, it doesnt work. 'use strict';
var o={x:0};
function caculate(args) {
o.x=args[0]+args[1] + 1;
}
function setNoDelay() {
const argsLen = arguments.length;
const args = new Array(argsLen);
for (var i = 0; i < argsLen; i++)
args[i] = arguments[i];
caculate(args);
}
function setNoDelay2(noDelay) {
caculate([noDelay]);
}
var common = require('../common.js');
var bench = common.createBenchmark(main, {
n: [1000000],
name: ['setNoDelay', 'setNoDelay2']
}, {});
function main(conf) {
var n = conf.n;
var method = conf.name === 'setNoDelay' ? setNoDelay : setNoDelay2;
var i;
bench.start();
for (i = 0; i < n; i++) {
method(1,2);
}
console.log(o.x);
bench.end(n);
} Difference! |
@simonkcleung the benchmark test case is for copy arguments item vs literal Array instance. When parameters count is 2, should change the |
@JacksonTian Right! I think I overlooked something. |
0888be0
to
3dd353a
Compare
I updated the commits by review suggestion. Would like to review it again? @mscdex |
I'm not sure the benchmark is worth including really. I don't think there will ever be a case when the loop will ever be faster than the explicit array literal case. |
@mscdex Let me remove the benchmark. |
When parameter count is fixed, use literal Array instance is more simply and avoid arguments leak also.
LGTM if CI is ok with it: https://ci.nodejs.org/job/node-test-pull-request/5960/ |
Landed aa8eb87 |
When parameter count is fixed, use literal Array instance is more simply and avoid arguments leak also. PR-URL: #10833 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
When parameter count is fixed, use literal Array instance is more simply and avoid arguments leak also. PR-URL: #10833 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
Would require a backport PR if it should land on v6 or v4 |
When parameter count is fixed, use literal Array instance is more
simply and avoid arguments leak also.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
http