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

lib: make navigator not runtime-lookup process.version, arch, or platform #53765

Merged
merged 1 commit into from
Jul 15, 2024

Conversation

ljharb
Copy link
Member

@ljharb ljharb commented Jul 8, 2024

Preserves #53649.

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/startup
  • @nodejs/web-standards

@nodejs-github-bot nodejs-github-bot added lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Jul 8, 2024
@ljharb ljharb force-pushed the fix-navigator-bug branch 3 times, most recently from 1aa58ab to 4002f74 Compare July 8, 2024 20:35
@@ -85,6 +85,10 @@ const {
},
} = internalBinding('util');

require('internal/process/arch'); // Ensure the process arch is cached
require('internal/process/platform'); // Ensure the process platform is cached
require('internal/process/version'); // Etnsure the process version is cached
Copy link
Member

Choose a reason for hiding this comment

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

I have a feeling these will slow down startup.

Copy link
Member Author

Choose a reason for hiding this comment

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

They very well might, but since it's just three values i'm hoping not.

This comment was marked as resolved.

Copy link
Member

Choose a reason for hiding this comment

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

@joyeecheung can you take a look?

Copy link
Member

Choose a reason for hiding this comment

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

@ljharb I would prefer not to worsen this.

Copy link
Member

@joyeecheung joyeecheung Jul 9, 2024

Choose a reason for hiding this comment

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

The problem is not “three small modules would not themselves regress startup”, but that if we continue with this pattern, we end up with hundreds of modules that inevitably regress startup. If this is not something universally used by all applications, then it should be lazy loaded, or put into an existing file already loaded on startup. See #45659 (comment) and #45849

Copy link
Member Author

Choose a reason for hiding this comment

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

navigator is lazy loaded already. For the process pieces, I’d love suggestions of a better way to ensure the original values are used here - all i was able to come up with were these tiny modules. (an alternative is making a single module that’s a shallow copy of a subset of the process object)

Copy link
Member

@benjamingr benjamingr left a comment

Choose a reason for hiding this comment

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

This LGTM though I think it's fine to remove the lib/internal/bootstrap code (they're required in lib/internal/navigator which is hopefully/presumably lazily loaded). That should also resolve @mcollina's concern

@aduh95
Copy link
Contributor

aduh95 commented Jul 8, 2024

Benchmark CI: https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/1577/

Results
                                                                                          confidence improvement accuracy (*)   (**)  (***)
misc/startup-cli-version.js count=30 cli='deps/corepack/dist/corepack.js'                                 0.03 %       ±0.07% ±0.09% ±0.11%
misc/startup-cli-version.js count=30 cli='deps/npm/bin/npm-cli.js'                                        0.03 %       ±0.15% ±0.19% ±0.25%
misc/startup-cli-version.js count=30 cli='deps/npm/bin/npx-cli.js'                                        0.04 %       ±0.18% ±0.24% ±0.31%
misc/startup-cli-version.js count=30 cli='tools/eslint/node_modules/eslint/bin/eslint.js'        ***      0.19 %       ±0.06% ±0.08% ±0.11%
misc/startup-core.js count=30 mode='process' script='benchmark/fixtures/require-builtins'                 0.25 %       ±0.37% ±0.49% ±0.64%
misc/startup-core.js count=30 mode='process' script='test/fixtures/semicolon'                             0.29 %       ±3.43% ±4.57% ±5.94%
misc/startup-core.js count=30 mode='process' script='test/fixtures/snapshot/typescript'          ***      1.05 %       ±0.05% ±0.07% ±0.09%
misc/startup-core.js count=30 mode='worker' script='benchmark/fixtures/require-builtins'                 -0.05 %       ±0.21% ±0.28% ±0.36%
misc/startup-core.js count=30 mode='worker' script='test/fixtures/semicolon'                              0.09 %       ±0.35% ±0.47% ±0.61%
misc/startup-core.js count=30 mode='worker' script='test/fixtures/snapshot/typescript'                   -0.71 %       ±1.03% ±1.37% ±1.78%

@ljharb
Copy link
Member Author

ljharb commented Jul 8, 2024

@benjamingr i couldn't get it to work without the bootstrap, i think precisely because navigator is lazy loaded.

@ljharb ljharb force-pushed the fix-navigator-bug branch 5 times, most recently from 77899c0 to 0f7da61 Compare July 8, 2024 22:11
@anonrig anonrig requested a review from jasnell July 8, 2024 22:26
lib/internal/navigator.js Outdated Show resolved Hide resolved
lib/internal/navigator.js Outdated Show resolved Hide resolved
@ljharb ljharb force-pushed the fix-navigator-bug branch from 0f7da61 to 0acb361 Compare July 8, 2024 23:06
@ljharb ljharb requested a review from anonrig July 8, 2024 23:10
@ljharb ljharb force-pushed the fix-navigator-bug branch from 0acb361 to 263e61d Compare July 8, 2024 23:11
lib/internal/bootstrap/node.js Outdated Show resolved Hide resolved
test/parallel/test-bootstrap-modules.js Outdated Show resolved Hide resolved
@ljharb ljharb force-pushed the fix-navigator-bug branch from 263e61d to d5ccfd4 Compare July 9, 2024 04:04
lib/internal/bootstrap/node.js Outdated Show resolved Hide resolved
@ljharb ljharb force-pushed the fix-navigator-bug branch from d5ccfd4 to 2b020c8 Compare July 9, 2024 16:55
@ljharb
Copy link
Member Author

ljharb commented Jul 9, 2024

Updated; I went with just adding properties to the existing per-thread object to avoid creating an extra object, but I can certainly nest them in their own object (and try to come up with a name for it) if that's preferred.

@ljharb ljharb requested review from joyeecheung and daeyeon July 9, 2024 16:56
@aduh95 aduh95 added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Jul 11, 2024
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jul 11, 2024
@nodejs-github-bot
Copy link
Collaborator

@ljharb ljharb force-pushed the fix-navigator-bug branch from abf95d3 to 8a25835 Compare July 15, 2024 18:59
@ljharb
Copy link
Member Author

ljharb commented Jul 15, 2024

@aduh95 aduh95 added the request-ci Add this label to start a Jenkins CI on a PR. label Jul 15, 2024
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jul 15, 2024
@nodejs-github-bot
Copy link
Collaborator

@ljharb ljharb force-pushed the fix-navigator-bug branch from 8a25835 to 42edb23 Compare July 15, 2024 20:46
@ljharb ljharb force-pushed the fix-navigator-bug branch from 42edb23 to e0437ed Compare July 15, 2024 20:56
@nodejs-github-bot
Copy link
Collaborator

@aduh95 aduh95 added the commit-queue Add this label to land a pull request using GitHub Actions. label Jul 15, 2024
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Jul 15, 2024
@nodejs-github-bot nodejs-github-bot merged commit 04e08ad into nodejs:main Jul 15, 2024
53 checks passed
@nodejs-github-bot
Copy link
Collaborator

Landed in 04e08ad

@ljharb ljharb deleted the fix-navigator-bug branch July 15, 2024 23:16
aduh95 pushed a commit that referenced this pull request Jul 16, 2024
Preserves #53649.

PR-URL: #53765
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
aduh95 pushed a commit that referenced this pull request Jul 16, 2024
Preserves #53649.

PR-URL: #53765
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@aduh95 aduh95 mentioned this pull request Jul 16, 2024
ehsankhfr pushed a commit to ehsankhfr/node that referenced this pull request Jul 18, 2024
Preserves nodejs#53649.

PR-URL: nodejs#53765
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@joyeecheung
Copy link
Member

I just noticed that this actually led to a performance regression and defeated #53649 - the eagerly computed locale via Intl is taking up a whopping 30% of the startup time.
Screen Shot 2024-08-09 at 00 36 17

@joyeecheung
Copy link
Member

Also, technically locale is runtime-dependent and should not be computed at startup - we don't update the locale dynamically in core currently but addons can use LocaleConfigurationChangeNotification() to update it dynamically, and the right behavior in that case is to reflect this in navigator.language (I think it'll need V8 to expose the computed default locale to implement it properly, however).

@targos targos added the dont-land-on-v20.x PRs that should not land on the v20.x-staging branch and should not be released in v20.x. label Sep 21, 2024
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. dont-land-on-v20.x PRs that should not land on the v20.x-staging branch and should not be released in v20.x. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.