AgentSkillsCN

performance-analyzer

分析查询与代码变更对性能的影响。能够识别 N+1 查询、缺失索引、同步循环中的性能瓶颈、未分页的 fetch 操作、缺乏缓存优化、低效算法等问题。适用于数据库查询变更、循环逻辑调整、API 接口更新、大型文件操作,或涉及 fetch/查询/循环/映射/过滤等关键字时使用。

SKILL.md
--- frontmatter
name: performance-analyzer
description: Analyzes performance impact of query and code changes. Detects N+1 queries, missing indexes, sync-in-loops, unpaginated fetches, missing memoization, inefficient algorithms. Use for database query changes, loops, API changes, large file ops, or keywords fetch/query/loop/map/filter.

Performance Impact Analyzer

When to Trigger

  • Database query changes
  • Adding loops or iterations
  • API route modifications
  • Large file operations
  • Keywords: "fetch", "query", "loop", "map", "filter"

What to Do

Step 1: Detect Anti-Patterns

Check for:

  1. N+1 queries
  2. Missing database indexes
  3. Synchronous operations in loops
  4. Large data fetches without pagination
  5. Missing memoization (React)
  6. Inefficient algorithms (O(n²) or worse)

Step 2: Estimate Impact

Report current vs after (e.g. query count, time). Explain why slower (e.g. N+1).

Step 3: Suggest Optimizations

  • Replace N+1 with single query using include/select or JOINs.
  • Add indexes for filtered/sorted columns.
  • Add pagination (skip/take or cursor).
  • Use useMemo/useCallback where appropriate.
  • Prefer single aggregation over multiple sequential queries.

Show SLOW vs FAST code snippets. Ask: "Apply optimized version? (yes/no)".