Repository navigation
Bind node:console's _stdout and _stderr lazily - #8777
Conversation
There was a problem hiding this comment.
Superseded by the review of
bc24945f.
This review, of 3f3c53f8
✅ Approved — A small, self-contained change that keeps the old property semantics and is covered by a new test; no issues found.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
📋 Code Quality: ✅ LGTM
The lazy _stdout and _stderr accessors keep the old property semantics: they are configurable and enumerable, and assigning one replaces the stream. They follow the descriptor pattern already used for process.stdout and process.stderr. Every read in internal_console.ts goes through the property. The new test checks caching, that each accessor matches the process stream, and reassignment, and it restores the original streams afterwards.
📝 Documentation: ✅ LGTM
The new code comment describes how the code behaves now and why, as the repository's comment guidelines ask.
Reviewed commit: 3f3c53f8
process.stdout and process.stderr are accessors that load the stdio
streams, and with them the fs and streams modules, on first access.
node:console read both at the top level to set console._stdout and
console._stderr, so importing it paid for that whole module graph.
In this patch _stdout and _stderr are accessors that read the process
stream on first access and keep it, as Node.js does for its global
console. Assigning one replaces the stream, as before. A Worker that
reads one pays the same as before, at that point instead of at import.
Cost over an empty worker, medians of 150 interleaved runs:
before after
import, first isolate 5.91 ms 1.58 ms (3.7x)
import, extra isolate 4.75 ms 1.33 ms (3.6x)
import + _stdout, first isolate 6.10 ms 5.53 ms (-9.3%, noise)
import + _stdout, extra isolate 4.81 ms 4.96 ms (+3.1%, noise)
3f3c53f to
bc24945
Compare
There was a problem hiding this comment.
✅ Approved — A small, self-contained change that keeps the old property semantics and is covered by a new test; no issues found.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
📋 Code Quality: ✅ LGTM
The lazy _stdout and _stderr accessors keep the old property semantics: they are configurable and enumerable, and assigning one replaces the stream. They follow the descriptor pattern already used for process.stdout and process.stderr. Every read in internal_console.ts goes through the property. The new test checks caching, that each accessor matches the process stream, and reassignment, and it restores the original streams afterwards.
📝 Documentation: ✅ LGTM
The new code comment describes how the code behaves now and why, as the repository's comment guidelines ask.
Reviewed commit: bc24945f — same changes as 3f3c53f8, so this is that commit's review (no new review was run; line numbers are as of 3f3c53f8)
process.stdoutandprocess.stderrare accessors that load the stdio streams, and with them the fs and streams modules, on first access.node:consoleread both at the top level to setconsole._stdoutandconsole._stderr, so importing it paid for that whole module graph.In this patch
_stdoutand_stderrare accessors that read the process stream on first access and keep it, as Node.js does for its global console. Assigning one replaces the stream, as before. A Worker that reads one pays the same as before, at that point instead of at import. A new case inconsole-nodejs-test.jschecks both.import 'node:console', first isolateimport 'node:console', each extra isolateconsole._stdout, first isolateconsole._stdout, each extra isolateMedians of 150 interleaved runs of
workerd testwith 1 and 9 services,-c opt, Linux x86-64.