-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
benchmark: allow benchmarks to specify flags #10448
Conversation
IMHO just explicitly adding |
@mscdex There might be other flags needed in the future(e.g. from what I've grepped from the tests, GC flags, harmony flags, warning flags, |
/cc @nodejs/benchmarking @AndreasMadsen (Aside: Do we need to update @nodejs/benchmarking membership? Kind of surprised @AndreasMadsen isn't in there, for starters.) |
Pinging @nodejs/benchmarking is pretty weird anyway, even @mscdex isn’t on it. |
It is much better to implement these things in
so just adding this to If I understand correctly the problem is to call |
@Trott the benchmarking working group has very little to do with |
@AndreasMadsen I looked into the code a little bit futher, and If I understand correctly, Maybe the hints can be provided as: // This gets passed in both phases
// Flags: --expose-internals
// This gets passed when main is run, implemented in common.js
// RuntimeFlags: --max_old_space_size=1024
// This gets passed when main is compiled, implemented in compare.js and friends
// CompileTimeFlags: --harmony This also makes it possible to pass other flags than the hard-corded If you think this unnecessary, please let me know. But even if we don't implement this feature, I think at least the benchmark doc should mention this caveat ( |
@joyeecheung I'm not sure what the difference between compiling and running is in a JIT context. My guess is that you think Whatever solution we come up with it should be possible to run benchmarks using just |
@AndreasMadsen By running and compiling I was referring to the running/compiling of the benchmark script. So I looked into the code and turns out I somehow had a delusion that the script would get compiled once in https://github.com/nodejs/node/blob/master/benchmark/common.js#L26 and run once in https://github.com/nodejs/node/blob/master/benchmark/common.js#L24, but in fact it's compiled/run twice. So all the code in the benchmark script compiled by V8 in the first pass would not be relevant to those in the second pass, and in the first pass try {
console.log(process.execArgv, process.argv.slice(2));
const URL = require('internal/url').URL;
} catch(e) {
console.log(e);
} would print:
This is not a problem if the code outside
I agree. So if we still keep the |
Sounds like a good idea, I think benchmark/README.md#creating-a-benchmark would be the ideal place. |
2ff958b
to
8e1bb68
Compare
@AndreasMadsen So I revisited this PR again today and realized that if we want to make sure:
Then the best way for benchmarks to specify the flags that they wish to be run with is to pass them into |
d8835d2
to
0b39f45
Compare
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.
Yes, adding it as an option to createBenchmark
makes a lot more sense. I've sugested a few changes:
@@ -138,7 +139,7 @@ Benchmark.prototype._run = function() { | |||
|
|||
const child = child_process.fork(require.main.filename, childArgs, { | |||
env: childEnv, | |||
execArgv: ['--expose_internals'].concat(process.execArgv) | |||
execArgv: ['--expose_internals', ...self.flags, ...process.execArgv] |
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.
unfortunately common.js
needs to run on old node versions.
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.
Thanks for this heads up :)
@@ -3,17 +3,18 @@ | |||
const child_process = require('child_process'); | |||
const http_benchmarkers = require('./_http-benchmarkers.js'); | |||
|
|||
exports.createBenchmark = function(fn, options) { | |||
return new Benchmark(fn, options); | |||
exports.createBenchmark = function(fn, options, flags) { |
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 it would be better to make it exports.createBenchmark = function(fn, config, options)
, where options
is an object e.g. { flags: [] }
. I don't know why config
is called options
here, when it is not really optional.
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 agree. I also noticed that the docs name the second argument configs
, so I will use configs
as the local variable name here.
run the benchmarks with will be used. In the second pass, | ||
the `main` function will be run, and the process will be run with: | ||
|
||
* `--expose_internals` |
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 we should simplify it, such that --expose_internals
is added explicitly in whatever tests it is required. You can just search for require('/internal
.
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.
Yeah, I think it's simpler. (And from what I've grepped, there is only one benchmark uses this :P)
* Give createBenchmark and the Benchmark constructor a third argument for specifying the command line flags that this benchmark should be run with. The benchmarks are no longer run with --expose-internals by default, they will need to explicitly pass the flags. * Rename options to configs in createBenchmark and the Benchmark constructor to match the documentation since they are not optional. * Comment the properties of a Benchmark object
0b39f45
to
e132e7e
Compare
@AndreasMadsen I've updated the commits, with some more comments added to the properties of |
```js | ||
'use strict'; | ||
const common = require('../common.js'); | ||
const SlowBuffer = require('buffer').SlowBuffer; | ||
|
||
const bench = common.createBenchmark(main, { | ||
// If you want to benchmark the internal modules, add |
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.
nit: you ready wrote this in the options
object and in the main
function. I think saying it once is fine.
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.
Addressed :)
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, only a minor nit.
* Add detailed description of the arguments of `createBenchmark` * Describe the two passes of running the benchmarks * Suggest what kind of code should go where in the benchmark example
e132e7e
to
f3f864c
Compare
Ping @mscdex, I see @AndreasMadsen requested a review. |
LGTM |
If there are no more concerns about this I am going to land it. Inclined to land as two separate commits because the commit message could be a tad long if concatenated. |
Two approvals and no issues, landing sounds good to me. I'd just go for one commit, I don't think a long commit log is an issue (if you feel it's going into too much detail you can always remove some of it). |
* Give createBenchmark and the Benchmark constructor a third argument for specifying the command line flags that this benchmark should be run with. The benchmarks are no longer run with --expose-internals by default, they will need to explicitly pass the flags. * Rename options to configs in createBenchmark and the Benchmark constructor to match the documentation since they are not optional. * Comment the properties of a Benchmark object Also improve the documentation about creating benchmarks * Add detailed description of the arguments of `createBenchmark` * Describe the two passes of running the benchmarks * Suggest what kind of code should go where in the benchmark example PR-URL: #10448 Reviewed-By: Andreas Madsen <[email protected]> Reviewed-By: Brian White <[email protected]>
Landed in 2826e63. Thanks! |
* Give createBenchmark and the Benchmark constructor a third argument for specifying the command line flags that this benchmark should be run with. The benchmarks are no longer run with --expose-internals by default, they will need to explicitly pass the flags. * Rename options to configs in createBenchmark and the Benchmark constructor to match the documentation since they are not optional. * Comment the properties of a Benchmark object Also improve the documentation about creating benchmarks * Add detailed description of the arguments of `createBenchmark` * Describe the two passes of running the benchmarks * Suggest what kind of code should go where in the benchmark example PR-URL: #10448 Reviewed-By: Andreas Madsen <[email protected]> Reviewed-By: Brian White <[email protected]>
This does not land cleanly in LTS. Added dont-land label. Please feel free to manually backport |
It should not be backported, the entire benchmark suite was rewritten in v7 and declared a major change. |
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
benchmark
Description of change
This PR makes it possible for the benchmarks to indicate what execution flags should be passed in when they are run, similar to the way tests do this.EDIT: the intent of this PR has changed (#10448 (comment))
createBenchmark
and theBenchmark
constructor a third argument for specifying the command line flags that this benchmark should be run with.Background: #10439