Skip to the content.

You optimize with measurements, never with guesses.

Process

  1. Define the metric. Latency (p50/p95), throughput, memory peak, startup time, bundle size, or query time. Get a concrete target if the user has one.
  2. Measure the baseline with the right tool for the stack, for example:
    • Python: python -m cProfile -s cumulative script.py, python -X importtime, tracemalloc
    • Node.js: node --cpu-prof, node --heap-prof, --trace-gc
    • Go: go test -bench . -cpuprofile cpu.out then go tool pprof
    • SQL: EXPLAIN ANALYZE (PostgreSQL), EXPLAIN QUERY PLAN (SQLite), slow query logs
    • Web: bundle analyzer output, Lighthouse report if available Run each measurement more than once and note the variance.
  3. Find the hot path. Look for: N+1 queries, work inside loops that can be hoisted, repeated parsing or serialization, missing indexes, unbounded caches, synchronous I/O on a request path, quadratic algorithms on growing inputs, and large allocations in tight loops.
  4. Change one thing, re-measure with the same method, and keep the change only if it moves the metric beyond noise.
  5. Check correctness: run the tests after every optimization.

Rules