Skip to content

Conversation

@mcollina
Copy link
Member

@mcollina mcollina commented Jan 9, 2026

Summary

Add SyncTransform, a high-performance synchronous transform stream based on the syncthrough npm package.

Unlike the standard Transform stream, SyncTransform uses a synchronous transformation function (no callback), which results in significantly better performance (~10x faster).

Key Features

  • Synchronous transform function for better performance
  • Strict backpressure enforcement without internal buffering
  • Works with pipeline(), pipe(), and 'data' events
  • Supports object mode automatically
  • Includes flush function for final data emission

Example

const { SyncTransform, pipeline } = require('node:stream');
const { createReadStream } = require('node:fs');

pipeline(
  createReadStream('input.txt'),
  SyncTransform((chunk) => chunk.toString().toUpperCase()),
  process.stdout,
  (err) => {
    if (err) console.error(err);
  }
);

Caveats

  1. Strict backpressure: Writing before piping buffers exactly one chunk
  2. Single destination: Only one pipe() destination allowed
  3. No readable event: Data pushed directly to destination
  4. Either pipe() or 'data': Cannot use both simultaneously
  5. Object mode by default: Handles objects without explicit configuration

Add SyncTransform, a high-performance synchronous transform stream
based on the syncthrough npm package. Unlike the standard Transform
stream, SyncTransform uses a synchronous transformation function
(no callback), which results in significantly better performance.

Key features:
- Synchronous transform function for ~10x better performance
- Strict backpressure enforcement without internal buffering
- Works with pipeline(), pipe(), and 'data' events
- Supports object mode automatically
- Includes flush function for final data emission

PR-URL: https://github.com/nodejs/node/pull/XXXXX
@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/streams

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. stream Issues and PRs related to the stream subsystem. labels Jan 9, 2026
@ronag
Copy link
Member

ronag commented Jan 9, 2026

Awesome! But I have opinions... it's unfortunate that it tries to pretend to be a node stream even when it's clearly not.

I would prefer if it instead in some way was a construct for pipeline/compose. Something like:

pipeline(src, pipeline.map(chunk => chunk), dst, () => {})

The implementation could also be simpler then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. stream Issues and PRs related to the stream subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants