liveBook · Manning

Compute-bound

As explained in JavaScript in Depth

A condition in which computation consumes enough processor time to limit a program's responsiveness.

Compute-bound work keeps the main thread busy with expensive computation, limiting throughput and increasing response times. A hot function points to this bottleneck; event-loop delay can produce the same symptom for other reasons. section 11.3

In high-throughput streams, promise allocation and scheduling can add significant overhead to synchronous CPU work. That cost is generally less visible when each chunk waits on I/O. Keep synchronous work synchronous instead of routing it through a promise-based transform. section 10.4.5 section 10.7.1

Separate a CPU bottleneck from other causes of event-loop delay:

  • A CPU bottleneck means expensive computation occupies the main thread; a profile shows a genuinely hot function. section 11.3
  • Event-loop delay means tasks are waiting; long synchronous work, garbage-collection pauses, or microtask draining can contribute. section 11.3
// Web Streams
const transform = new TransformStream({
  async transform(chunk, controller) {
    const result = processChunk(chunk);  // #A
    controller.enqueue(result);
  }
});

Compare this promise-based Web Streams transform with the synchronous Node.js transform. section 10.7.1

const transform = new stream.Transform({
  transform(chunk, encoding, callback) {
    callback(null, processChunk(chunk));
  }
});

See the synchronous Node.js transform alternative. section 10.7.1

How JavaScript in Depth covers it

How deep it goes
Traces per-chunk promise overhead and distinguishes hot computation from waiting, without developing a diagnostic procedure.
Examples
Compares Web Streams and Node.js transforms processing synchronous chunks.
What you can do after
Apply it by keeping synchronous CPU work in a plain function or Node.js synchronous transform.
How it connects
Connects CPU-bound work to Web Streams, Node.js streams, promises, and event-loop delay.

Also explained in

Compare how 9 books explain compute-bound →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of JavaScript in Depth. The section links point to the parts of the book it draws on.