-
Notifications
You must be signed in to change notification settings - Fork 30k
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
Conversation
Review requested:
|
1aa58ab
to
4002f74
Compare
lib/internal/bootstrap/node.js
Outdated
@@ -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 |
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.
I have a feeling these will slow down startup.
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.
They very well might, but since it's just three values i'm hoping not.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
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.
@joyeecheung can you take a look?
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.
@ljharb I would prefer not to worsen this.
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.
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
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.
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)
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 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
Benchmark CI: https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/1577/ Results
|
@benjamingr i couldn't get it to work without the bootstrap, i think precisely because navigator is lazy loaded. |
77899c0
to
0f7da61
Compare
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. |
abf95d3
to
8a25835
Compare
(rebased, and included updating https://github.com/nodejs/node/pull/53817/files#diff-26e6b1e2a90040b1ce20e7f305b2ff3140b483f863ee2573b4c6af9b696ad31eR1472, per request) |
8a25835
to
42edb23
Compare
42edb23
to
e0437ed
Compare
Landed in 04e08ad |
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>
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>
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>
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. |
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). |
Preserves #53649.