Performance: Why child processes are needed
HIGH IMPACT
This concept affects how Node.js handles CPU-intensive tasks and parallel work, impacting responsiveness and throughput.
import { fork } from 'child_process'; const child = fork('heavyTask.js'); child.on('message', msg => console.log(msg));
const heavyTask = () => { while(true) {} }; heavyTask();| Pattern | CPU Blocking | Event Loop Delay | Memory Overhead | Verdict |
|---|---|---|---|---|
| Synchronous heavy task in main process | Blocks CPU fully | Blocks event loop causing high INP | Low memory but poor responsiveness | [X] Bad |
| Heavy task in child process | Runs in parallel CPU | Event loop remains free, low INP | Higher memory due to extra process | [OK] Good |