Sitelet https://github.com/nodejs/node/issues/54465
Skip to content

Persist the V8 code cache before spawning a child process #54465

Description

@merceyz

What is the problem this feature will solve?

NODE_COMPILE_CACHE persists the V8 code cache when the process is terminating which means that if the script spawns itself then that child process wont benefit from the cache.

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

Persist the V8 code cache before spawning a child process so it can benefit from the cache.

import { execFileSync } from "child_process";

if (process.argv[2] === "foo") {
	console.log("foo");
} else {
	// Persist the V8 code cache
	console.log(execFileSync("node", ["test.mjs", "foo"]).toString());
}

What alternatives have you considered?

No response

Activity

  1. joyeecheung commented on Aug 21, 2024

    @joyeecheung
    Member

    I wonder if we should just provide an API for the user to tell Node.js to persist the cache of modules already loaded (that would be similar to v8.takeCoverage() which flushes the coverage accumulated via NODE_V8_COVERAGE to disk). It can be tricky to persist the cache implicitly for any child process calls - either it needs to be blocking, then it could actually make the child process calls wait for it if the cache is big enough, or it needs to be non-blocking, then it's questionable whether the new child process actually get to pick it up - it might finish startup earlier than the persistence of the cache completes. Only the party spawning the child process knows what is the best for the kind of child process that they are spawning.

    Also I am not sure how big of a problem this is - you won't get to pick up the cache the first time this application is launched, but you will get it the second time the application is launched anyway. Both the main and the child processes will pick it up from the same store, so the coverage is only missing for the child processes in the first launch.

  2. joyeecheung commented on Sep 16, 2024

    @joyeecheung
    Member

    Opened #54971

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues requesting new Node.js features.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions