Chapter 15: Performance and cost

Now for what a machine can do at once, which depends on what the work really is.

Concurrency and parallelism

Concurrency means juggling many tasks, swapping between them while each waits for something. Parallelism means truly doing several at the same instant, on separate cores, the independent workers inside a CPU. Waiting can be juggled. Crunching numbers needs more cores.

An agent will happily wrap heavy work in Promise.all and call it parallel. That speeds up work that waits, such as network calls, and does nothing for work that computes, because in JavaScript it all still takes turns on one thread. Ask which kind of work it is, then time it.

Say it to your agent

“Promise.all won't speed up hashing these files, because that work is CPU and not waiting. Move the hashing to a pool of worker_threads with one worker per core, time it against the current version on the same 200 files, and show me both numbers.”

The workshop

Name a word, or describe what you mean in everyday language.