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

Enable bytecode caching to reduce time cost on require() #45106

Closed
lucshi opened this issue Oct 21, 2022 · 7 comments
Closed

Enable bytecode caching to reduce time cost on require() #45106

lucshi opened this issue Oct 21, 2022 · 7 comments
Labels
feature request Issues that request new features to be added to Node.js. stale

Comments

@lucshi
Copy link

lucshi commented Oct 21, 2022

What is the problem this feature will solve?

When discussing the CSP FaaS teams, the top concern is the start up time of their FaaS framework. The framework is usually programmed by JS and contains only a few lines of require(), e.g. require("FC_core"); require("FC_meter");require("payment");.
In real world measurement, the framework usually takes hundreds of millionsecond to start up. Majority time is spent on parsing and compiling hundred of modules during require().

What is the feature you are proposing to solve the problem?

Enable byte code caching in the first run and serialize the cache onto disk, and deserialize the byte code caching in following runs. It will be enabled by runtime parameters and by default disabled due to hurt memory usage.

I'm asking whether it will be an accepted method.

What alternatives have you considered?

No response

@lucshi lucshi added the feature request Issues that request new features to be added to Node.js. label Oct 21, 2022
@bnoordhuis
Copy link
Member

On-disk code caching has been discussed in the past. One problem is that the bytecode (and code caching in general) is specific to the V8 version and V8 command line flags, possibly even the machine it's running on.

For example, it's unspecified what happens when --use_strict is set during loading but not during compilation (or vice versa.)

V8 doesn't really guard against mismatches either so if you get it wrong, things are likely to go boom in unpredictable ways.


Another problem is that creating the code cache is relatively slow, it's essentially object serialization.

It's definitely going to regress cold boots (first-time run, nothing cached) so the wins for warm boots should be substantial to make up for that. Needs careful benchmarking.

@targos
Copy link
Member

targos commented Oct 21, 2022

node --build-snapshot and node --snapshot-blob (experimental) can be used to speed up application startup time.

https://nodejs.org/dist/latest-v19.x/docs/api/cli.html#--build-snapshot
https://nodejs.org/dist/latest-v19.x/docs/api/cli.html#--snapshot-blobpath

@lucshi
Copy link
Author

lucshi commented Oct 23, 2022

node --build-snapshot and node --snapshot-blob (experimental) can be used to speed up application startup time.

https://nodejs.org/dist/latest-v19.x/docs/api/cli.html#--build-snapshot https://nodejs.org/dist/latest-v19.x/docs/api/cli.html#--snapshot-blobpath

Thank you!

@bnoordhuis
Copy link
Member

Web snapshots may also make it more tractable if/when it stabilizes (still gated behind --experimental_web_snapshots.)

@github-actions
Copy link
Contributor

There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment.

For more information on how the project manages feature requests, please consult the feature request management document.

@github-actions github-actions bot added the stale label Apr 23, 2023
@fmmoret
Copy link

fmmoret commented Apr 23, 2023

I'll make a comment to keep this open.

Based on what I've seen in node 20, some of the ground work is being done that makes this possible for userland code and maybe is already done. IIRC, I had seen @joyeecheung doing God's work

@bnoordhuis
Copy link
Member

I'll close this as it's largely a duplicate of #47472. That issue is younger but has a lot more discussion.

@bnoordhuis bnoordhuis closed this as not planned Won't fix, can't repro, duplicate, stale Apr 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js. stale
Projects
None yet
Development

No branches or pull requests

4 participants