perf: avoid loading full node:stream module in internal modules - #27400
Draft
sosukesuzuki wants to merge 5 commits into
Draft
sosukesuzuki wants to merge 5 commits into
sosukesuzuki wants to merge 5 commits into
Conversation
Replace require('node:stream') with direct submodule requires:
- require('internal/streams/readable')
- require('internal/streams/writable')
- require('internal/streams/end-of-stream')
This avoids eagerly loading unused submodules (Transform, Duplex,
PassThrough, pipeline, operators, etc.) when accessing process.stdin,
fs.createReadStream, or fs.createWriteStream.
Benchmark shows ~0.5ms improvement in process.stdin startup cost.
Apply the same optimization to: - node/zlib.ts: Transform, finished - node/_http_server.ts: Duplex, Stream - node/_http2_upgrade.ts: Duplex - node/http2.ts: Readable, Duplex, Stream - thirdparty/undici.js: Readable - builtins/CompressionStream.ts: Readable, Writable - builtins/DecompressionStream.ts: Readable, Writable Each file now requires only the specific internal/streams/* submodules it needs instead of the full node:stream module.
Collaborator
|
Updated 11:20 AM PT - Feb 27th, 2026
❌ @sosukesuzuki, your commit 2529997 has 6 failures in
🧪 To try this PR locally: bunx bun-pr 27400That installs a local version of the PR into your bun-27400 --bun |
end-of-stream exports the eos function as default export, not as
a named 'finished' export. Using { finished } destructuring caused
ERR_INVALID_ARG_TYPE because the callback was passed as options.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replace
require("node:stream")with direct submodule requires (internal/streams/readable,internal/streams/writable, etc.) in files that only use a subset of the stream module. This avoids eagerly loading unused submodules (Transform, Duplex, PassThrough, pipeline, operators, etc.) at startup.Changed files
src/js/internal/fs/streams.ts—Readable,Writable,finishedsrc/js/node/zlib.ts—Transform,finishedsrc/js/node/_http_server.ts—Duplex,Streamsrc/js/node/_http2_upgrade.ts—Duplexsrc/js/node/http2.ts—Readable,Duplex,Streamsrc/js/thirdparty/undici.js—Readablesrc/js/builtins/CompressionStream.ts—Readable,Writablesrc/js/builtins/DecompressionStream.ts—Readable,WritableBenchmark (
process.stdinstartup cost, release build, median of 50 runs × 3 rounds)process.stdinrequire("node:stream")fs.createReadStreamrequire("node:stream")itself is unchanged, confirming the improvement comes from avoiding unnecessary submodule loading.