A synchronous callback can delay unrelated work: while it occupies the main thread, other callbacks wait, making I/O appear slow. In a stream transform, genuinely synchronous work need not be wrapped in an async function; doing so adds promise and microtask overhead without useful I/O waiting. section 10.7.1 section 11.1.9
Use the observed delay to guide the investigation:
- If event loop delay is high, check for GC pauses; if GC is not responsible, inspect synchronous JavaScript with a CPU profile. section 11.3.1
- Keep CPU-bound transform work synchronous when possible; reserve async transforms for work that genuinely waits on I/O. section 10.7.1
- When I/O latency rises, compare it with event loop delay to distinguish local blocking from slow network or remote service behavior. section 11.1.9
const transform = new stream.Transform({
transform(chunk, encoding, callback) {
callback(null, processChunk(chunk));
}
});A Node.js transform callback processes a chunk synchronously without creating a promise. section 10.7.1
// Web Streams
const transform = new TransformStream({
async transform(chunk, controller) {
const result = processChunk(chunk); // #A
controller.enqueue(result);
}
});A Web Streams transform uses an async method even when its chunk-processing work is synchronous. section 10.7.1











