Repository navigation
Load process and Buffer lazily with the new module registry - #8815
Conversation
There was a problem hiding this comment.
Superseded by the review of
853ea980.
This review, of ef092db8
💬 Approved with comments — The change is correct and safe. The one WARNING is a stale developer reference document that still describes the removed process/Buffer warm-up, and it has no runtime impact.
Findings: 1 warning
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
🔧 Fix with your agent
Paste the following into your coding agent to investigate and fix these issues.
Fix the following code review issues found in pull request #8815.
Before making changes, review each issue and present a brief summary table:
- For each finding, state whether you agree, disagree, or need clarification
- If you disagree (e.g., the fix would require disproportionate changes
for minimal ROI, or the finding is factually incorrect), explain why
- If you need to clarify something before deciding, ask those questions
- Then share your plan for which issues to tackle and in what order
## WARNING (1)
### [Documentation] docs/reference/detail/new-module-registry.md:829-832 still describes the nodejs_compat_v2 process/buffer warm-up in worker.c++, which this pull request removes. The flag is now checked in the lazy process/Buffer getters in api/global-scope.c++.
- **File:** docs/reference/detail/new-module-registry.md:831
📝 Documentation: ⚠️ 1 warning
The new module registry reference still describes the removed process/Buffer warm-up.
Recommendation: 📝 Minor Comments
- [WARNING] docs/reference/detail/new-module-registry.md:829-832 still describes the nodejs_compat_v2 process/buffer warm-up in worker.c++, which this pull request removes. The flag is now checked in the lazy process/Buffer getters in api/global-scope.c++. (
docs/reference/detail/new-module-registry.md:831)
View full review
Lines 829-832 of docs/reference/detail/new-module-registry.md still list "the nodejs_compat_v2 process/buffer warm-up" among the worker.c++ flag-check sites. This pull request removes that warm-up from worker.c++. The process and Buffer getters in api/global-scope.c++ now check the flag themselves when they resolve their module lazily. Update the sentence so it describes those getters, in line with the repository's rule that documents describe the current state of the code.
✅ All other checks passed
🔒 Security: ✅ LGTM
No security-relevant changes.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md updates needed.
📋 Code Quality: ✅ LGTM
Both getters resolve their module inside a ModuleEvaluationScope only when the new registry is enabled, and they re-check the cached value after resolving. featureFlags in worker.c++ is still used by the timers block, so removing the pre-resolve leaves no dead variable. The optional chaining in emitWarning() drops a warning only when no process object exists yet, so nothing can be listening for it.
⚡ Performance: ✅ LGTM
Loading these modules lazily removes per-isolate startup work and adds no new cost on the hot path.
Reviewed commit: ef092db8
ef092db to
853ea98
Compare
There was a problem hiding this comment.
Superseded by the review of
c821c4a6.
This review, of 853ea980
✅ Approved — The earlier documentation warning is fixed, and I found nothing else to raise. Loading these modules lazily is correct and limited to the new module registry.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
The getters resolve fixed built-in specifiers that no user input reaches. No access-control or isolation check changes.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md updates needed.
📋 Code Quality: ✅ LGTM
Both getters open a ModuleEvaluationScope only when the new registry is enabled, and they check the cached value again after resolving. Removing the warm-up in worker.c++ leaves no unused variable. The emitWarning() guard drops a warning only when no process object exists yet.
⚡ Performance: ✅ LGTM
Removing the warm-up takes work off every isolate's startup. A first access adds no cost on the hot path.
📝 Documentation: ✅ LGTM
docs/reference/detail/new-module-registry.md now lists the lazy process and Buffer getters in global-scope.c++ as flag-check sites, which matches the code.
Reviewed commit: 853ea980
emitWarning() emits the warning on the process object from a microtask, but the process object is only set once its module has loaded, on first use. A warning raised before then, such as the MaxListenersExceededWarning from a node:events emitter that has too many listeners, threw "Cannot read properties of undefined (reading 'emit')" from the microtask. This happens with the legacy module registry today. The new registry loads the process module before every Worker, which hides it. In this patch the warning is dropped when the process object isn't set. Nothing can have a 'warning' listener before then, so emitting it would have had no effect. Compatibility: no flag. The only change is that a microtask that threw a TypeError now does nothing, which is what the same warning does once the process module has loaded and has no 'warning' listener.
With the new module registry, every isolate evaluated the process module (node-internal:public_process or legacy_process) and node:buffer before the main module, even for a Worker that never touches them. nodejs_compat_v2 is on by date, so this ran with or without nodejs_compat and cost about 1.3 ms of startup per isolate. The legacy registry loads both on first access. The pre-resolve was there so that a first access during top-level evaluation wouldn't drain the microtask queue. require() no longer drains while a module is evaluating, so that case is covered without it. In this patch the pre-resolve is removed, and the process and Buffer getters resolve their module inside a ModuleEvaluationScope when the new registry is in use. A first access during a request therefore still doesn't run the Worker's pending microtasks, as it doesn't today. Both modules are synchronous built-ins, so they settle without a drain. The legacy registry path is unchanged. Compatibility: no flag. The process and buffer modules now evaluate on first use instead of before the main module, as they do with the legacy registry. Microtask behaviour on first access is unchanged.
The process and Buffer globals load their modules on first access with the new module registry. A Worker that queues a microtask and then reads either global for the first time must not see the microtask run inside the getter, in a request or during top-level evaluation. A built-in that emits a process warning before the process module has loaded must not fail. In this patch new-module-registry-lazy-globals-test covers the first access in a request and at top level, and checks the globals are the node:process and node:buffer exports. The request case fails if the getters resolve without a ModuleEvaluationScope. It also raises a MaxListenersExceededWarning from node:events with each registry before anything loads the process module, which fails without the emitWarning() fix.
853ea98 to
c821c4a
Compare
There was a problem hiding this comment.
✅ Approved — No findings. process and Buffer now load lazily only under the new module registry, and the emitWarning() guard drops a warning only when no process object exists yet.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
The getters resolve fixed built-in specifiers, and no user input reaches them. No access-control or isolation check changes.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md updates needed.
📋 Code Quality: ✅ LGTM
global-scope.c++:getBuffer()andgetProcess()open aModuleEvaluationScopeonly whenisNewModuleRegistryEnabled(FeatureFlags::get(js))is true. That leaves the legacy path unchanged. Both getters check the cached value again after resolving.worker.c++: removing the pre-resolve block leaves no unused variable.internal_process.ts: the guard drops a warning only when the process object is not set yet.- Tests: they cover a first access during a request and during top-level evaluation, and the warning case with both registries.
⚡ Performance: ✅ LGTM
Removing the eager pre-resolve takes work off every isolate's startup. A first access adds no cost on the hot path.
📝 Documentation: ✅ LGTM
docs/reference/detail/new-module-registry.md matches the code.
Reviewed commit: c821c4a6
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8815 +/- ##
==========================================
- Coverage 68.00% 67.73% -0.28%
==========================================
Files 847 847
Lines 219245 215043 -4202
Branches 32592 32590 -2
==========================================
- Hits 149097 145655 -3442
+ Misses 50903 50145 -758
+ Partials 19245 19243 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
With the new module registry, every isolate evaluates the process module (
node-internal:public_processorlegacy_process) andnode:bufferbefore the main module, even for a Worker that never touches them.nodejs_compat_v2is on by date, so this happens with or withoutnodejs_compat, and it makes each new isolate start about 1.3 ms slower than with the legacy registry, which loads both on first access. The pre-resolve was added so that a first access during top-level evaluation wouldn't drain the microtask queue, butrequire()no longer drains while a module is evaluating, so that case is already covered.In this patch the pre-resolve is removed, and the
processandBuffergetters resolve their module inside aModuleEvaluationScopewhen the new registry is in use. A first access during a request still doesn't run the Worker's pending microtasks, as it doesn't today, and both modules are synchronous built-ins that settle without a drain. The legacy registry path is unchanged.process.emitWarning()emits on the process object from a microtask, and that object is only set once the process module has loaded. A warning raised before then, such as the MaxListenersExceededWarning from anode:eventsemitter, threw a TypeError from the microtask. This already happens with the legacy registry, and loading lazily would have exposed it with the new one too, so the first commit drops the warning when there is no process object yet. Nothing can be listening for it then.The new
new-module-registry-lazy-globals-testcovers a first access in a request and during top-level evaluation, and the warning with both registries. The request case fails without the scope, and the warning cases fail without theemitWarning()fix.nodejs_compatnodejs_compatCPU time to start the Worker in a fresh isolate, median of 400
workerd benchstartup samples per cell, both binaries interleaved,-c opton a 4-CPU Linux x86-64 machine. A Worker that imports everynode:built-in is unchanged (15.4 vs 15.1 ms), and so is the first isolate of a process.Part of #8365.