Skip to content

fix(ext/node): upgrade node:stream #28855

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 14, 2025

Conversation

littledivy
Copy link
Member

@littledivy littledivy commented Apr 11, 2025

Ref #28836

This PR replaces the outdated _streams.mjs bundle with an auto-managed, file-by-file port of Node.js stream internals using the ext/node/update_node_stream.ts script.

TBD:

  • Get it to compile
  • All tests pass
  • Enable more tests
  • Performance (size diff? snapshot deserde?)

Performance

Binary size (aarch64-apple-darwin): 85396664 bytes (+140KB from main)

Startup time:

$ hyperfine 'target/release/deno run empty.js' './deno_main run empty.js'
Benchmark 1:
  Time (mean ± σ):      20.6 ms ±   0.8 ms    [User: 14.4 ms, System: 5.0 ms]
  Range (min … max):    19.6 ms …  22.9 ms    123 runs

Benchmark 2:
  Time (mean ± σ):      19.8 ms ±   0.6 ms    [User: 14.2 ms, System: 5.0 ms]
  Range (min … max):    19.4 ms …  22.3 ms    125 runs

@littledivy littledivy changed the title fix(ext/node): upgrade node:streams fix(ext/node): upgrade node:stream Apr 11, 2025
Copy link
Member

@ry ry Apr 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dsherret because this involves code transpilation, it'd be good to get your eyes.

@littledivy littledivy force-pushed the streams-nightmare branch 4 times, most recently from 0319ace to 82367f4 Compare April 13, 2025 03:49
@littledivy littledivy added the ci-draft Run the CI on draft PRs. label Apr 13, 2025
@littledivy littledivy force-pushed the streams-nightmare branch 2 times, most recently from 80fe5e8 to 82e758d Compare April 13, 2025 09:16
@littledivy littledivy removed the ci-draft Run the CI on draft PRs. label Apr 13, 2025
@littledivy littledivy marked this pull request as ready for review April 13, 2025 09:16
Comment on lines 5 to 6
// This file is used to transform Node.js internal streams code to
// Deno polyfills.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you expand this description? This file is only run when we want to upgrade the node streams code?

Can you use TypeScript instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ported to TypeScript

Comment on lines 53 to 55
// Workaround a bug in our formatter: "export default from;" does not work
// correctly, so we rename it to something else and export.
const renameForDefaultExport = ["from"];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you open a dprint issue and link it here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like an swc syntax error.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it can parse it on the swc playground

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an swc diagnostic that's not surfaced in the playground. I'll open an swc issue.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@dsherret dsherret Apr 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

swc-project/swc#10372 -- Using identifiers that are also contextual keywords is kind of asking to hit edge cases.

@littledivy littledivy force-pushed the streams-nightmare branch 2 times, most recently from 6aa984f to 257132a Compare April 13, 2025 17:18
Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - this is a massive improvement!

@littledivy littledivy merged commit 01b6da9 into denoland:main Apr 14, 2025
18 checks passed
nathanwhit pushed a commit that referenced this pull request Apr 14, 2025
Ref #28836

This PR replaces the _stream.mjs bundle with a file-by-file port instead. A codemod transpiles Node.js internals to ESM. The codemod performs three tasks: translating CJS to ESM, remapping internal dependencies, and hoisting lazy requires as imports.

The process is fully automated through the `update_node_stream.ts` script, simplifying future internal updates. The script checks out Node.js from a specific tag defined in the `tests/node_compat/runner`.

Additionally, the update enables new tests in our Node test runner and adds features (like compose()) that were missing from the outdated bundle.

## Performance

There is a 140KB+ binary size increase on aarch64-apple-darwin and nop startup time stays the same.
nathanwhit pushed a commit that referenced this pull request Apr 14, 2025
Ref #28836

This PR replaces the _stream.mjs bundle with a file-by-file port instead. A codemod transpiles Node.js internals to ESM. The codemod performs three tasks: translating CJS to ESM, remapping internal dependencies, and hoisting lazy requires as imports.

The process is fully automated through the `update_node_stream.ts` script, simplifying future internal updates. The script checks out Node.js from a specific tag defined in the `tests/node_compat/runner`.

Additionally, the update enables new tests in our Node test runner and adds features (like compose()) that were missing from the outdated bundle.

## Performance

There is a 140KB+ binary size increase on aarch64-apple-darwin and nop startup time stays the same.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants