Skip to content

typescript.cpu_in_event_loop

Performance High

Detects CPU-intensive operations that block Node.js event loop.

Blocking event loop:

  • All requests stalled — Single-threaded Node.js freezes
  • Timeouts — Other operations time out
  • Poor scalability — Can’t handle concurrent load
// ❌ Before (blocking event loop)
app.get('/hash', (req, res) => {
const hash = crypto.pbkdf2Sync(req.body.password, salt, 100000, 64, 'sha512');
res.json({ hash: hash.toString('hex') });
});
// ✅ After (offload to worker)
import { Worker } from 'worker_threads';
app.get('/hash', async (req, res) => {
const hash = await runInWorker(req.body.password);
res.json({ hash });
});
// Or use async version:
app.get('/hash', async (req, res) => {
const hash = await new Promise((resolve, reject) => {
crypto.pbkdf2(req.body.password, salt, 100000, 64, 'sha512', (err, key) => {
if (err) reject(err);
else resolve(key.toString('hex'));
});
});
res.json({ hash });
});
  • Sync crypto operations in request handlers
  • Large JSON.parse/stringify in hot paths
  • Heavy loops without yielding