--- description: Performance — avoid N+1, cache wisely, measure before optimizing alwaysApply: false --- # Performance - Measure before optimizing. Profile hot paths; do not guess bottlenecks. - Fix N+1 queries: use eager loading, joins, or batch fetches. - Cache expensive reads with explicit TTL and invalidation strategy. - Lazy-load heavy modules and routes not needed on initial page load. - Paginate large lists — never load unbounded datasets into memory. - Debounce search inputs and resize handlers (typically 200–300ms). - Compress and resize images. Serve modern formats (WebP, AVIF) where supported. - Avoid blocking the main thread with heavy sync work — use workers or server-side processing. - Set appropriate HTTP cache headers for static assets.