2.4 KiB
2.4 KiB
Performance Awareness
Frontend Performance
Bundle Size
- Avoid importing entire libraries — use tree-shakable imports
- Dynamic
import()for heavy components (modals, editors, charts) - Check:
@next/bundle-analyzerif bundle grows unexpectedly - Never import server-only code in client components
Rendering
- Memoize expensive computations with
useMemo/useCallbackonly when profiling shows a bottleneck — not preemptively - Avoid prop drilling through many layers — use stores or context at the right level
- Keep
useEffectdependency arrays tight — stale closures are better caught by the TypeScript hook than by runtime bugs
Images & Media
- Always use
next/imagewith explicit width/height orfill+sizes - Lazy-load below-the-fold images (default in next/image)
- Video thumbnails: use S3 presigned URLs with appropriate cache headers
Backend Performance
Database Queries
- Always use
.options(selectinload(...))or.options(joinedload(...))for related data — N+1 queries are the #1 backend perf killer - Add
.limit()to any query that could return unbounded results - Use
EXPLAIN ANALYZE(via DB Architect agent or MCP postgres) before optimizing — measure, don't guess - Index foreign keys and columns used in WHERE/ORDER BY
Async Patterns
- Never use
time.sleep()— useasyncio.sleep()in async code - Never call sync I/O (file reads, HTTP requests) in async endpoints — use
run_in_executoror async libraries - Dramatiq tasks are sync — that's fine, they run in worker processes
Caching
- Use Redis for frequently-accessed, rarely-changed data (user settings, project metadata)
- Cache at service layer, not repository layer
- Always set TTL — no unbounded caches
Remotion Performance
- Keep composition prop data minimal — don't pass full transcription objects, pass pre-processed caption arrays
- Use
delayRender/continueRenderfor async data loading in compositions - Prefer
interpolate()overspring()for simple animations — springs are heavier
Agent Model Selection
When dispatching subagents, consider token cost:
- Sonnet (default): Standard development work, code generation, reviews
- Haiku: Lightweight lookups, simple code transformations, data extraction
- Opus: Complex architectural decisions, deep analysis, ambiguous requirements
Use model: "haiku" parameter on Agent tool for cheap, focused tasks.