Performance: CPU profiling basics
CPU profiling helps identify how much processor time your Node.js code consumes, affecting responsiveness and throughput.
Jump into concepts and practice - no test required
import { Worker } from 'worker_threads'; const worker = new Worker(new URL('./heavyComputation.js', import.meta.url)); worker.on('message', () => console.log('Done'));
function heavyComputation() {
for (let i = 0; i < 1e9; i++) {}
}
heavyComputation();| Pattern | CPU Usage | Event Loop Blocking | Responsiveness Impact | Verdict |
|---|---|---|---|---|
| Synchronous heavy computation | High CPU | Blocks event loop for 100+ ms | High INP, poor responsiveness | [X] Bad |
| Offloading to worker threads | High CPU but parallel | No main thread blocking | Low INP, smooth responsiveness | [OK] Good |
--prof.--prof, others are invalid flags.node --prof app.jsnode --prof-process isolate-0x12345-v8.log--prof-process?node --prof app.js but no log file was created. What is a likely cause?--prof and exits normally.node --prof app.js and get a log file. What is the correct next step to analyze this data?node --prof-process on the log file converts it into a readable report showing CPU usage per function.