FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

lib: make navigator not runtime-lookup process.version, arch, or platform by ljharb · Pull Request #53765 · nodejs/node · GitHub

/ node Public

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

Merged
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
ljharb:fix-navigator-bug
Jul 15, 2024
Merged

lib: make navigator not runtime-lookup process.version, arch, or platform#53765
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
ljharb:fix-navigator-bug

Conversation

ljharb commented Jul 8, 2024
edited
Loading

Copy link
Copy Markdown
Member

Preserves #53649.

Copy link
Copy Markdown
Collaborator

Review requested:

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

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 force-pushed the fix-navigator-bug branch 3 times, most recently from 1aa58ab to 4002f74 Compare July 8, 2024 20:35
Comment thread lib/internal/bootstrap/node.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I have a feeling these will slow down startup.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

This comment was marked as resolved.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

@joyeecheung can you take a look?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

@ljharb I would prefer not to worsen this.

joyeecheung Jul 9, 2024
edited
Loading

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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)

Comment thread test/parallel/test-navigator.js Outdated

benjamingr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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 commented Jul 8, 2024
edited
Loading

Copy link
Copy Markdown
Contributor

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 commented Jul 8, 2024

Copy link
Copy Markdown
Member Author

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

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

ljharb commented Jul 9, 2024
edited
Loading

Copy link
Copy Markdown
Member Author

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 requested review from daeyeon and joyeecheung July 9, 2024 16:56
aduh95 added the author ready PRs that have at least one approval, no outstanding review comments, and a CI started. label Jul 11, 2024
github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jul 11, 2024

Copy link
Copy Markdown
Collaborator

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

ljharb commented Jul 15, 2024

Copy link
Copy Markdown
Member Author

aduh95 added the request-ci Add this label to start a Jenkins CI on a PR. label Jul 15, 2024
github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jul 15, 2024

Copy link
Copy Markdown
Collaborator

ljharb force-pushed the fix-navigator-bug branch from 8a25835 to 42edb23 Compare July 15, 2024 20:46
Comment thread lib/internal/process/per_thread.js Outdated
ljharb force-pushed the fix-navigator-bug branch from 42edb23 to e0437ed Compare July 15, 2024 20:56

Copy link
Copy Markdown
Collaborator

aduh95 added the commit-queue Add this label to land a pull request using GitHub Actions. label Jul 15, 2024
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 merged commit 04e08ad into nodejs:main Jul 15, 2024

Copy link
Copy Markdown
Collaborator

Landed in 04e08ad

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 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>

Copy link
Copy Markdown
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.

Copy link
Copy Markdown
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).

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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 outstanding review comments, and a CI started. 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.


Back | FazBrowse Home | New Git URL