lazy load these requires so that node:cluster imports faster (#14291)

This commit is contained in:
Meghan Denny
2024-10-02 02:30:19 -07:00
committed by GitHub
parent 25083a4252
commit b8a2a11c6f
2 changed files with 6 additions and 2 deletions

View File

@@ -1,7 +1,8 @@
const net = require("node:net");
const { append, init, isEmpty, peek, remove } = require("internal/linkedlist");
const { kHandle } = require("internal/shared");
let net;
const sendHelper = $newZigFunction("node_cluster_binding.zig", "sendHelperPrimary", 4);
const ArrayIsArray = Array.isArray;
@@ -20,6 +21,7 @@ export default class RoundRobinHandle {
server;
constructor(key, address, { port, fd, flags, backlog, readableAll, writableAll }) {
net ??= require("node:net");
this.key = key;
this.all = new Map();
this.free = new Map();

View File

@@ -1,5 +1,4 @@
const EventEmitter = require("node:events");
const child_process = require("node:child_process");
const Worker = require("internal/cluster/Worker");
const RoundRobinHandle = require("internal/cluster/RoundRobinHandle");
const path = require("node:path");
@@ -8,6 +7,8 @@ const { throwNotImplemented, kHandle } = require("internal/shared");
const sendHelper = $newZigFunction("node_cluster_binding.zig", "sendHelperPrimary", 4);
const onInternalMessage = $newZigFunction("node_cluster_binding.zig", "onInternalMessagePrimary", 3);
let child_process;
const ArrayPrototypeSlice = Array.prototype.slice;
const ObjectValues = Object.values;
const ObjectKeys = Object.keys;
@@ -86,6 +87,7 @@ function createWorkerProcess(id, env) {
// ArrayPrototypePush(execArgv, `--inspect-port=${getInspectPort(cluster.settings.inspectPort)}`);
// }
child_process ??= require("node:child_process");
return child_process.fork(cluster.settings.exec, cluster.settings.args, {
cwd: cluster.settings.cwd,
env: workerEnv,