This is a discussion / follow-up issue, not a bug report. Release is already unblocked by #5153 — nothing here is urgent or blocking. Just capturing a design question from #4914 so it isn't lost in a merged-PR thread.
Context. To make global.gc() available in production npm installs, #4914 added a dist/cli-entry.js bin wrapper that re-spawns node --expose-gc cli.js (and forwards args/stdio/signals). This is the OOM-prevention hardening, and the goal is clearly worth doing.
The question. Is the wrapper the right way to get there? The cost is a second node process held for the whole CLI lifetime, plus the manual forwarding. Meanwhile the compaction is doing the real OOM work, and the code already degrades gracefully when gc() isn't available (memoryPressureMonitor.ts just logs and skips). So it's worth asking whether the extra process is buying enough to justify itself.
Possible directions (just to seed discussion, not a proposal):
- Keep
--expose-gc for dev/opt-in only, and rely on graceful degradation in production — no wrapper.
- Expose
gc at runtime instead of via a launch flag (v8.setFlagsFromString('--expose_gc') + vm.runInNewContext('gc')) — one line, no wrapper, no extra process.
- Keep the wrapper as-is if there's a reason production explicit-gc is important enough to warrant it.
No strong opinion on the outcome — mainly want to make sure the tradeoff gets a deliberate look. Refs #4914, #5153.
中文说明
这是一个讨论 / follow-up issue,不是 bug。 release 已由 #5153 解锁,这里的内容都不紧急、不阻塞。只是把 #4914 的一个设计问题记下来,免得埋在已合并的 PR 讨论里。
背景。 为了让生产 npm 安装里 global.gc() 可用,#4914 加了个 dist/cli-entry.js wrapper,它会 re-spawn node --expose-gc cli.js(并转发参数/stdio/信号)。这是 OOM 加固,目标本身明确值得做。
问题。 wrapper 是不是实现这个目标的合适方式?代价是常驻一个跑满整个 CLI 生命周期的第二个 node 进程,外加手动转发。而真正防 OOM 的是 compaction,且 gc() 不可用时代码本来就优雅降级(memoryPressureMonitor.ts 只是 log 一下跳过)。所以值得问一句:这个额外进程换来的收益,够不够撑起它自己。
几个可能方向(只为引出讨论,不是定论):
--expose-gc 只留给 dev/opt-in,生产靠优雅降级——不要 wrapper。
- 运行时暴露
gc 而非靠启动 flag(v8.setFlagsFromString('--expose_gc') + vm.runInNewContext('gc'))——一行,无 wrapper、无额外进程。
- 如果有理由认为生产显式 gc 足够重要,也可以维持现状。
对结论没有强偏好,主要想确保这个取舍被认真看一眼。Refs #4914、#5153。
This is a discussion / follow-up issue, not a bug report. Release is already unblocked by #5153 — nothing here is urgent or blocking. Just capturing a design question from #4914 so it isn't lost in a merged-PR thread.
Context. To make
global.gc()available in production npm installs, #4914 added adist/cli-entry.jsbin wrapper that re-spawnsnode --expose-gc cli.js(and forwards args/stdio/signals). This is the OOM-prevention hardening, and the goal is clearly worth doing.The question. Is the wrapper the right way to get there? The cost is a second
nodeprocess held for the whole CLI lifetime, plus the manual forwarding. Meanwhile the compaction is doing the real OOM work, and the code already degrades gracefully whengc()isn't available (memoryPressureMonitor.tsjust logs and skips). So it's worth asking whether the extra process is buying enough to justify itself.Possible directions (just to seed discussion, not a proposal):
--expose-gcfordev/opt-in only, and rely on graceful degradation in production — no wrapper.gcat runtime instead of via a launch flag (v8.setFlagsFromString('--expose_gc')+vm.runInNewContext('gc')) — one line, no wrapper, no extra process.No strong opinion on the outcome — mainly want to make sure the tradeoff gets a deliberate look. Refs #4914, #5153.
中文说明
这是一个讨论 / follow-up issue,不是 bug。 release 已由 #5153 解锁,这里的内容都不紧急、不阻塞。只是把 #4914 的一个设计问题记下来,免得埋在已合并的 PR 讨论里。
背景。 为了让生产 npm 安装里
global.gc()可用,#4914 加了个dist/cli-entry.jswrapper,它会 re-spawnnode --expose-gc cli.js(并转发参数/stdio/信号)。这是 OOM 加固,目标本身明确值得做。问题。 wrapper 是不是实现这个目标的合适方式?代价是常驻一个跑满整个 CLI 生命周期的第二个 node 进程,外加手动转发。而真正防 OOM 的是 compaction,且
gc()不可用时代码本来就优雅降级(memoryPressureMonitor.ts只是 log 一下跳过)。所以值得问一句:这个额外进程换来的收益,够不够撑起它自己。几个可能方向(只为引出讨论,不是定论):
--expose-gc只留给dev/opt-in,生产靠优雅降级——不要 wrapper。gc而非靠启动 flag(v8.setFlagsFromString('--expose_gc')+vm.runInNewContext('gc'))——一行,无 wrapper、无额外进程。对结论没有强偏好,主要想确保这个取舍被认真看一眼。Refs #4914、#5153。