Knowledge Base/Advanced Topics/Performance Optimization

Performance Optimization

Performance work has diminishing returns — pull these levers in order, and stop when the app feels fast. Each one is a prompt away; you don't have to profile by hand.

The levers, in order

  1. Database indexes. Ask "what indexes does this app need based on the queries it runs?" — usually the biggest win for the least effort.
  2. Kill N+1 queries. "Find N+1 patterns and rewrite them as a single join." Loading a list that fires one query per row is the most common slowdown.
  3. Trim the frontend bundle. "Switch the admin pages to dynamic imports so they don't ship in the customer bundle."
  4. Cache hot reads. Add Redis (or in-memory in dev) for sessions, dashboards, and plan limits.
  5. Put static assets on a CDN with long cache headers.

Measure first

  • Before optimizing, ask the AI to add simple timing logs to the slow endpoint, or check the browser's Network tab.
  • Optimizing the wrong thing is wasted effort — fix what the numbers actually point to.
  • Re-measure after each change so you know it helped.

Front-end quick wins

  • Lazy-load routes that aren't on the critical path.
  • Paginate long lists instead of rendering thousands of rows.
  • Compress and size images correctly for where they're shown.

Common mistakes to avoid

  • Optimizing before measuring. You'll polish the fast parts and miss the slow one.
  • Caching stale data. Cache reads that rarely change; invalidate on writes.
  • Micro-optimizing. Indexes and N+1 fixes beat clever one-liners every time.

FAQ

My app feels slow — where do I start?

Indexes and removing N+1 queries solve most real slowness. Do those two before anything fancier.

Can the AI find the slow parts?

Yes — ask it to add timing logs or review the queries an endpoint runs, then propose fixes.

Do I need Redis?

Only once caching is the bottleneck. For many apps, indexes and pagination are enough.

Was this article helpful?