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 enterprisesprocess: specialize building and storage of process.config #24816
Conversation
This comment has been minimized.
This comment has been minimized.
nodejs-github-bot
added
the
lib / src
label
Dec 3, 2018
This comment has been minimized.
This comment has been minimized.
joyeecheung
requested review from
addaleax and
devsnek
and removed request for
addaleax
Dec 3, 2018
joyeecheung
reviewed
Dec 3, 2018
| @@ -9,7 +9,7 @@ const common = require('../common'); | |||
| const assert = require('assert'); | |||
|
|
|||
| const isMainThread = common.isMainThread; | |||
| const kMaxModuleCount = isMainThread ? 58 : 80; | |||
| const kMaxModuleCount = isMainThread ? 59 : 81; | |||
This comment has been minimized.
This comment has been minimized.
joyeecheung
Dec 3, 2018
Author
Member
This is incremented because previously we use getInternalBinding to load native_module which bypasses the caching and process.moduleLoadList bookkeeping. This patch uses internalBinding instead so it is now being counted into the process.moduleLoadList
devsnek
approved these changes
Dec 3, 2018
This comment has been minimized.
This comment has been minimized.
joyeecheung
force-pushed the
joyeecheung:process-config
branch
from
84e3a30
to
3bdcfd2
Dec 4, 2018
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
If you're going through all that preprocessing trouble anyway, can't you turn config.gypi into a real JS object literal, write that to a file and include it in the build? That gets rid of the overhead of deserializing it, too. |
This comment has been minimized.
This comment has been minimized.
|
@bnoordhuis Do you mean prefixing it with a |
This comment has been minimized.
This comment has been minimized.
|
I mean that you write a .js file that contains this: module.exports = {
target_defaults: {
// ...
},
variables: {
// ...
},
};I.e., don't store it as a string, store it as a JS object literal. |
This comment has been minimized.
This comment has been minimized.
|
@bnoordhuis But it will still be stored, in the binary, as a string, just like the source code of other builtin modules? So essentially we go from doing this
to
|
This comment has been minimized.
This comment has been minimized.
|
Right, but the plan is to move to precompiled snapshots eventually, isn't it? |
This comment has been minimized.
This comment has been minimized.
|
@bnoordhuis Eventually, maybe (I believe we are currently stuck on gyp refactoring)...but the result of JSON.parse can also be part of the snapshot? And it is somewhat clearer to me if the config gets some special treatment like this because it has to be treated specially in the end since it’s not require-able, and it’s eassentially data, not code. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Okay, fair enough. My point was more that if you're putting in the work to make it better, why not go the extra mile to make it great? The only reason it's using |
This comment has been minimized.
This comment has been minimized.
I think the reason would be, I personally think using JSON.parse is a better approach already? If ew do it with an object literal, aside from adding the And this brings us back to #24816 (comment) - we will be compiling and executing code to grab the data out instead of simply parsing it as data. It does unify the processing but config is already just different from other native modules - the generated content completely depends on how you run Or is there any reason that it's better to make the code of config executable? Like...making it require-able if you do a |
This comment has been minimized.
This comment has been minimized.
|
Also, I think if we keep it as JSON, we are still able to replace Lines 338 to 339 in 6ccc80c with something done via python. Currently, if you touch something in the docs, and you just had a bad build, this will error when you try building the binary again via EDIT: or maybe that's still possible if we do a rough search/regexp matching..but having it as JSON is simpler |
This comment has been minimized.
This comment has been minimized.
|
Also...if we are writing config.gypi as config.js, then we will need to rewrite this somehow: Lines 21 to 23 in 6ccc80c |
joyeecheung
force-pushed the
joyeecheung:process-config
branch
from
3bdcfd2
to
42ab2d3
Dec 6, 2018
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.
This comment has been minimized.
This comment has been minimized.
|
I plan to land this after the 7 day wait for single approval is passed and when I manage to get the CI green, because it's conflicting with another patch of mine to share the code cache among worker threads. Regarding rewriting |
This comment has been minimized.
This comment has been minimized.
Let's try to ping @nodejs/python first. |
This comment has been minimized.
This comment has been minimized.
|
Landed in 44a5fe1 |
joyeecheung
closed this
Dec 10, 2018
joyeecheung
added a commit
that referenced
this pull request
Dec 10, 2018
MylesBorins
added
the
backport-requested-v11.x
label
Dec 25, 2018
This comment has been minimized.
This comment has been minimized.
|
This doesn't land cleanly on v11.x, could it please be backported |
targos
added this to Backport requested
in v11.x
Dec 28, 2018
This comment has been minimized.
This comment has been minimized.
|
Ping @joyeecheung |
This comment has been minimized.
This comment has been minimized.
|
The following ancestor commits of 44a5fe1 are not on v11.x-staging
|
addaleax
added a commit
that referenced
this pull request
Jan 14, 2019
This comment has been minimized.
This comment has been minimized.
|
I’ve backported this to v11.x while resolving a tiny merge conflict in the counter in |
joyeecheung commentedDec 3, 2018
Instead of treating config.gypi as a JavaScript file, specialize
the processing in js2c and make the serialized result a real JSON
string (with 'true' and 'false' converted to boolean values) so
we don't have to use a custom deserializer during bootstrap.
In addition, store the JSON string separately in NativeModuleLoader,
and keep it separate from the map of the builtin source code, so
we don't have to put it onto
NativeModule._sourceand delete itlater, though we still preserve it in
process.binding('natives'),which we don't use anymore.
This patch also makes the map of builtin source code and the
config.gypi string available through side-effect-free getters
in C++.
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes