Skip to content
AgileLogics
4 min read

Performance Optimization & Profiling

Prerequisites: Testing strategies

Measure before optimizing — a profiler (like the one built into IntelliJ, or async-profiler) shows exactly where a running program actually spends its time and memory, rather than guessing.

Common, high-value fixes once a real bottleneck is found:

  • Choosing the right collection — a HashMap lookup is O(1), a linear search through a List is O(n); using the wrong one at scale is a frequent, easy-to-fix bottleneck.
  • Avoiding unnecessary object creation inside a hot loop (e.g. String concatenation with + instead of StringBuilder, revisited from Level 1 now at scale).
  • Batching database calls instead of issuing one query per item in a loop (the classic "N+1 query" problem).

Common mistakes

  • "Optimizing" code that isn't actually a bottleneck, based on a guess rather than a profiler's measurements — this often makes the code harder to read for no measurable benefit.