-
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
process: introduce process.availableV8flags #40791
Conversation
d7b3392
to
0368161
Compare
It would be good to get input from someone on the V8 team to see if they would be interested in making the list of flags available programmatically in some way. |
The reason for wanting to include this in core is to make https://www.npmjs.com/package/v8flags obsolete which has over 3 million weekly downloads and has comments in the source code like this // this entire module is depressing. i should have spent my time learning
// how to patch v8 so that these options would just be available on the
// process object. ...and this: // i can't wait for the day this whole module is obsolete because these
// options are available on the process object. this executes node with
// `--v8-options` and parses the result, returning an array of command
// line flags. /cc @phated This seems like a decent test case for our recently-added guide on whether to include things in core (which is about modules but there is an open PR to make it about functionality in general). |
Would the |
Copying the criteria from #40601 and putting checkmarks next to the ones that apply or might apply. 👇 Strong arguments for including a component in core
Strong arguments against including a component in core
|
Perhaps. I chose |
Thanks @Trott! I yearn for a day when all our hacks upon hacks are obsolete ❤️ |
0368161
to
1051af4
Compare
@nodejs/v8 |
1051af4
to
bf6d579
Compare
@nodejs/process |
bf6d579
to
e836284
Compare
An additional complication to hard-coding the flags (aside from the code smell) is that some flags don't exist on all platforms (such as |
this wouldn't be hard to expose from v8, they're in a big c array: https://source.chromium.org/chromium/chromium/src/+/main:v8/src/flags/flags.cc;drc=861cbcc13edb6281c5d1c7976553840136b1f897;l=379 |
I really don't like the hard-coded approach, because
|
Yeah, I expect that literally no one likes the hard-coded list approach, including me. |
Can't we add a simple script that extracts all the flags from the file Gus sent as an alternative approach? |
I would prefer not exposing all flags on the V8-side as we open up an additional API surface. To understand the problem a bit better:
Many V8-flags are just for debugging and internal development and should likely never be exposed in userland (and we obviously make our lives on the V8-side easy by not thinking too hard about which ones should be exposed) |
@@ -255,6 +256,82 @@ const replaceUnderscoresRegex = /_/g; | |||
const leadingDashesRegex = /^--?/; | |||
const trailingValuesRegex = /=.*$/; | |||
|
|||
class FlagsSet extends Set { |
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.
If the the reason for putting the feature under process
is code-sharing, this could be just split into a different file. I also think that v8
is a more appropriate place for it.
function buildAvailableV8Flags() { | ||
|
||
const v8Flags = [ | ||
'--abort-on-contradictory-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.
This doesn't look very reliable to me - V8 flags come and go and there are no guarantees about them. If possible we should do this programmatically, e.g. having a script that put them into a json file during every update and loading the json during build time, or just request v8 to expose a list of available flags through embedder API (that might be difficult to get accepted though).
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.
Yup, since the flags can come or go in any release, I added a test to check these flags against the output of node --v8-options
. Unfortunately, as if there wasn't already enough reason to be skeptical about a hardcoded list of flags, the test fails because some flags aren't available on some platforms. And that's not even getting into problems when Node.js is built with different configuration flags. So this won't work at all without a bunch of extra logic. So yeah, the hardcoded array is a total nonstarter which is not surprising.
I wonder if an alternative approach would be to provide an API that shows whether certain commonly used v8 flags that are not available (and if we don't know, or if it's available for now which also means they could go away soon, return undefined). IIUC the use case for such API is usually to check if a feature isn't supported in a particular build. We could have a set that records flags that are no longer available instead, and record the status of more flags in it as users request. Although in that case this still seems more like what a user land module should offer instead of something in core. |
No because they are not static. Some, for example, are platform-dependent. |
@phated Can you answer that question? I wonder if an API that accepts a string or an array of strings and returns a boolean indicating whether or not it is a valid V8 flag would meet the need. This avoids exposing an explicit list of V8 flags but allows tools to determine if something they've been handed is or isn't a V8 flag, assuming there's a compelling use case for that. |
Having something like |
I don't have any metrics on the flags people would use. We purposely expose them all so any flags that node or v8 accepts can be passed through a CLI tool, such that |
FYI, I've been slowly working towards making V8 flags read-only. |
Forever alone 😭 |
Yeah, sorry. I still support this, but I'm not nearly as involved in Node.js as I once was and this will require someone willing to put in the work, both politically and technically. (Er....unless someone has exposed something within V8 already that we can leverage?) |
I'm opening this so at least two things can be discussed: