Performance: CPU profiling basics
MEDIUM IMPACT
CPU profiling helps identify how much processor time your Node.js code consumes, affecting responsiveness and throughput.
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 |