Performance: Why timing matters in Node.js
HIGH IMPACT
This concept affects how fast Node.js can respond to requests and handle tasks without blocking the event loop.
import { readFile } from 'fs/promises'; async function readFiles() { const data1 = await readFile('file1.txt', 'utf8'); const data2 = await readFile('file2.txt', 'utf8'); console.log(data1, data2); } readFiles();
const fs = require('fs'); function readFiles() { const data1 = fs.readFileSync('file1.txt', 'utf8'); const data2 = fs.readFileSync('file2.txt', 'utf8'); console.log(data1, data2); } readFiles();
| Pattern | Event Loop Blocking | Task Delay | Responsiveness | Verdict |
|---|---|---|---|---|
| Synchronous blocking calls | Blocks event loop fully | Delays all queued tasks | High input latency | [X] Bad |
| Asynchronous non-blocking calls | Does not block event loop | Tasks run as soon as ready | Low input latency | [OK] Good |