Profiling and Performance Optimization

Node.js applications can be profiled using tools such as the Node inspector, CPU profiles, heap snapshots, and performance APIs. Production performance work should examine real bottlenecks such as database queries, network calls, serialization, event-loop delay, and memory pressure.

Useful optimizations include database indexing, batching, pagination, connection pooling, caching, stream processing, and algorithmic improvements.

Key Takeaways
  • Profile before optimizing.
  • Database and network latency are often more significant than JavaScript micro-optimizations.
  • Measure latency distributions such as p50, p95, and p99 rather than only averages.
Knowledge Check

What is usually the best first step before a performance optimization?