Performance: os module for system information
LOW IMPACT
Using the os module affects server-side performance by retrieving system info without blocking the event loop significantly.
const os = require('os'); let cachedSystemInfo = null; function getSystemInfo() { if (!cachedSystemInfo) { cachedSystemInfo = { cpus: os.cpus(), mem: os.totalmem(), freeMem: os.freemem() }; } return cachedSystemInfo; }
const os = require('os'); function getSystemInfo() { const cpus = os.cpus(); const mem = os.totalmem(); const freeMem = os.freemem(); // called repeatedly in a tight loop for(let i=0; i<10000; i++) { os.cpus(); } return { cpus, mem, freeMem }; }
| Pattern | CPU Usage | Event Loop Blocking | Memory Usage | Verdict |
|---|---|---|---|---|
| Repeated os calls in loop | High CPU usage | Blocks event loop for ms | Normal | [X] Bad |
| Cached os info retrieval | Low CPU usage | Minimal event loop blocking | Slightly higher memory for cache | [OK] Good |