Skip to content
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

src: cache the result of GetOptions() in JS land #24091

Closed
wants to merge 2 commits into from

Conversation

joyeecheung
Copy link
Member

Instead of calling into C++ each time we need to check the value
of a command line option, cache the option map in a new
internal/options module for faster access to the values in JS land.

Instead of calling into C++ each time we need to check the value
of a command line option, cache the option map in a new
`internal/options` module for faster access to the values in JS land.
@nodejs-github-bot nodejs-github-bot added the lib / src Issues and PRs related to general changes in the lib or src directory. label Nov 4, 2018
@joyeecheung
Copy link
Member Author

Copy link
Member

@addaleax addaleax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with 1 comment

@@ -211,8 +211,7 @@

NativeModule.isInternal = function(id) {
return id.startsWith('internal/') ||
(id === 'worker_threads' &&
!internalBinding('options').getOptions('--experimental-worker'));
(id === 'worker_threads' && !config.experimentalWorker);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we avoid going back to process.config? 😕

Copy link
Member Author

@joyeecheung joyeecheung Nov 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are also two other reference to config in here, I think a better option would probably be to just specialize something for NativeModule here - maybe just directly generate the whole map when the process starts and pass it to the loader bootstrapper here and let NativeModule short-circuit the internal/options implementation. That also opens up the opportunity to emit all the warning for experimental modules in one place here instead of emitting them everywhere across the code base.

EDIT: wait, we emit them regardless of the cli options..so never mind I guess

@joyeecheung
Copy link
Member Author

Fixed linter and the bootstrap module list test: https://ci.nodejs.org/job/node-test-pull-request/18336/

@joyeecheung
Copy link
Member Author

@refack
Copy link
Contributor

refack commented Nov 5, 2018

Instead of calling into C++ each time

I get that motivation, but couldn't we make it simpler? I'd be happy to share your reasoning.

@refack refack added process Issues and PRs related to the process subsystem. cli Issues and PRs related to the Node.js command line interface. labels Nov 5, 2018
@joyeecheung
Copy link
Member Author

@refack See #24091 (comment) my reasoning is we could just eliminate calling into C++ at all eventually by creating the map before bootstrapping loaders so it will be made available in loafers.js as an argument directly. This PR just moves the calls to a central place that can be manipulated in loaders.js

@refack
Copy link
Contributor

refack commented Nov 5, 2018

Resume: https://ci.nodejs.org/job/node-test-commit/22901/
(previous fail was infra, should be resolved)

@refack refack added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Nov 5, 2018
@joyeecheung
Copy link
Member Author

joyeecheung commented Nov 6, 2018

Just FYI there are others who disagree (that's one of the reasons test/parallel/test-bootstrap-modules.js exists

@refack Just to explore about this point a bit further - I think the reason why test/parallel/test-bootstrap-modules.js exists is to make sure we load less stuff during the bootstrap if they are not really necessary. In this case, the options have to be loaded during the bootstrap no matter what since it is conceptually a dependency of the bootstrap process (whereas things like TCPWrap really are not and they are the main targets that test/parallel/test-bootstrap-modules.js tests against).
In that regard, the length of the module load list is not a very effective measure, as the compilation of a very simple module like options.js that does not depend on too many other modules only incurs a very small overhead (whereas other bigger modules may incur a much bigger overhead by running code synchronously and even invoking bindings that do much more). But again, we don't actually have a better measure to evaluate the "weight" of these native modules..so that remains to be investigated.

@refack
Copy link
Contributor

refack commented Nov 6, 2018

I think the reason why test/parallel/test-bootstrap-modules.js exists is to make sure we load less stuff during the bootstrap if they are not really necessary.

Main reason sure, but it's also been quoted as a braier for adding new (trivial) modules - #23081 (review)

Again, I'm slightly in favor... Encapsulation/Performance is just a balance we should keep in mind.

@refack
Copy link
Contributor

refack commented Nov 6, 2018

ubuntu-on-arm had a flake, so resume again: https://ci.nodejs.org/job/node-test-commit/22902/

@Trott Trott closed this Nov 8, 2018
Trott pushed a commit to Trott/io.js that referenced this pull request Nov 8, 2018
Instead of calling into C++ each time we need to check the value
of a command line option, cache the option map in a new
`internal/options` module for faster access to the values in JS land.

PR-URL: nodejs#24091
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Refael Ackermann <refack@gmail.com>
@Trott
Copy link
Member

Trott commented Nov 8, 2018

Landed in f895b5a

BridgeAR pushed a commit that referenced this pull request Nov 14, 2018
Instead of calling into C++ each time we need to check the value
of a command line option, cache the option map in a new
`internal/options` module for faster access to the values in JS land.

PR-URL: #24091
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Refael Ackermann <refack@gmail.com>
kiyomizumia pushed a commit to kiyomizumia/node that referenced this pull request Nov 15, 2018
Instead of calling into C++ each time we need to check the value
of a command line option, cache the option map in a new
`internal/options` module for faster access to the values in JS land.

PR-URL: nodejs#24091
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Refael Ackermann <refack@gmail.com>
codebytere pushed a commit that referenced this pull request Dec 13, 2018
Instead of calling into C++ each time we need to check the value
of a command line option, cache the option map in a new
`internal/options` module for faster access to the values in JS land.

PR-URL: #24091
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Refael Ackermann <refack@gmail.com>
MylesBorins pushed a commit that referenced this pull request Dec 22, 2018
Instead of calling into C++ each time we need to check the value
of a command line option, cache the option map in a new
`internal/options` module for faster access to the values in JS land.

PR-URL: #24091
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Refael Ackermann <refack@gmail.com>
@MylesBorins MylesBorins mentioned this pull request Dec 22, 2018
MylesBorins pushed a commit that referenced this pull request Dec 25, 2018
Instead of calling into C++ each time we need to check the value
of a command line option, cache the option map in a new
`internal/options` module for faster access to the values in JS land.

PR-URL: #24091
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. cli Issues and PRs related to the Node.js command line interface. lib / src Issues and PRs related to general changes in the lib or src directory. process Issues and PRs related to the process subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants