review-performance

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Skill: Review Performance

Skill:性能评审

Purpose

目的

Review code for performance concerns only. Do not define scope (diff vs codebase) or perform security/architecture/language-framework convention analysis; those are handled by other atomic skills. Emit a findings list in the standard format for aggregation. Focus on algorithmic complexity, query efficiency, I/O and network cost, memory behavior, contention and concurrency bottlenecks, caching strategy, and measurable regression risk.

仅针对代码的性能问题进行评审。无需定义评审范围(如diff对比或整个代码库),也不进行安全/架构/语言框架规范分析;这些内容由其他原子技能负责。按照标准格式输出问题发现列表,以便进行汇总。重点关注算法复杂度、查询效率、I/O与网络成本、内存行为、竞争与并发瓶颈、缓存策略,以及可量化的退化风险。

Use Cases

适用场景

  • Orchestrated review: Used as a cognitive step when review-code runs scope -> language -> framework -> library -> cognitive.
  • Performance-focused review: When the user wants only performance dimensions checked before merge or release.
  • Regression prevention: Validate that changes do not introduce obvious latency, throughput, or memory regressions.
When to use: When the task includes performance review. Scope and code range are determined by the caller or user.

  • 编排式评审:在review-code执行范围→语言→框架→库→认知层面的评审流程时,作为认知步骤使用。
  • 聚焦性能的评审:当用户希望在合并或发布前仅检查性能维度时使用。
  • 退化预防:验证代码变更是否引入明显的延迟、吞吐量或内存退化问题。
使用时机:当任务包含性能评审需求时。评审范围和代码范围由调用方或用户确定。

Behavior

行为规范

Scope of this skill

本技能的评审范围

  • Analyze: Performance dimensions in the given code scope (files or diff provided by the caller). Do not decide scope; accept the code range as input.
  • Do not: Perform scope selection, security review, architecture review, or language/framework style review. Focus only on performance.
  • 分析内容:在给定的代码范围(调用方提供的文件或diff)内的性能维度问题。无需自行确定范围,直接接受提供的代码范围作为输入。
  • 禁止操作:不得进行范围选择、安全评审、架构评审或语言/框架风格评审。仅聚焦性能问题。

Review checklist (performance dimension only)

评审检查清单(仅性能维度)

  1. Complexity hotspots: Detect unnecessary O(n^2)+ behavior, repeated scans, nested loops over large collections, and avoidable recomputation.
  2. Database and query efficiency: N+1 access patterns, missing pagination, broad selects, inefficient joins/filters, and query frequency amplification.
  3. I/O and network cost: Chatty remote calls, missing batching, blocking calls on critical paths, unbounded retries/timeouts, and poor backoff behavior.
  4. Memory and allocations: Excessive allocations/churn, large object retention, unnecessary copies, unbounded growth, and avoidable buffering.
  5. Concurrency and contention: Lock contention, serialized critical sections, thread/goroutine starvation, queue backpressure, and oversubscription risks.
  6. Caching and reuse: Missing cache opportunities on hot read paths, invalidation correctness risks, stampede risk, and low-value cache layers.
  7. Load-facing behavior: Missing limits/guards (batch size, page size, concurrency caps), expensive defaults, and absent degradation strategy under load.
  8. Observability for performance: Missing metrics/tracing around hot paths that prevents regression detection and capacity planning.
  1. 复杂度热点:检测不必要的O(n^2)+级行为、重复扫描、针对大型集合的嵌套循环,以及可避免的重复计算。
  2. 数据库与查询效率:N+1访问模式、缺失分页、宽泛的查询语句、低效的关联/过滤逻辑,以及查询频率放大问题。
  3. I/O与网络成本:频繁的远程调用、缺失批量处理、关键路径上的阻塞调用、无限制的重试/超时,以及不合理的退避策略。
  4. 内存与分配:过度的内存分配/周转、大对象滞留、不必要的复制、无限制的内存增长,以及可避免的缓冲操作。
  5. 并发与竞争:锁竞争、序列化的关键代码段、线程/协程饥饿、队列背压,以及过度订阅风险。
  6. 缓存与复用:热点读路径上缺失缓存机会、缓存失效的正确性风险、缓存击穿风险,以及低价值的缓存层。
  7. 面向负载的行为:缺失限制/防护机制(如批量大小、分页大小、并发上限)、开销高昂的默认配置,以及负载下的降级策略缺失。
  8. 性能可观测性:热点路径上缺失指标/追踪,导致无法检测退化问题和进行容量规划。

Severity guidance

严重程度指南

  • critical: Clear production impact likely (e.g. unbounded loop/growth, repeated expensive I/O in hot path, catastrophic query pattern).
  • major: Strong regression or scalability risk with realistic traffic/data growth.
  • minor/suggestion: Localized or lower-impact optimization opportunities.
  • critical(严重):可能对生产环境造成明确影响(如无限循环/内存增长、热点路径中重复执行的高开销I/O、灾难性查询模式)。
  • major(主要):随着流量/数据增长,存在明显的退化或可扩展性风险。
  • minor/suggestion(次要/建议):局部或低影响的优化机会。

Tone and references

语气与参考要求

  • Professional and technical: Reference specific locations (file:line or query/block).
  • Emit findings with Location, Category, Severity, Title, Description, Suggestion.

  • 专业且技术化:引用具体位置(如文件:行号 或 查询/代码块标识)。
  • 输出的问题发现需包含位置、类别、严重程度、标题、描述、建议。

Input & Output

输入与输出

Input

输入

  • Code scope: Files or directories (or diff) already selected by the user or scope skill. This skill does not decide scope; it reviews the provided code for performance only.
  • 代码范围:由用户或范围技能已选定的文件、目录(或diff)。本技能不负责确定范围,仅针对提供的代码进行性能评审。

Output

输出

  • Emit zero or more findings in the format defined in Appendix: Output contract.
  • Category for this skill is cognitive-performance.

  • 输出零个或多个问题发现,格式需符合附录:输出约定中的定义。
  • 本技能对应的类别为cognitive-performance

Restrictions

限制条件

  • Do not perform scope selection, security, architecture, or language/framework style review. Stay within performance dimensions.
  • Do not give conclusions without specific locations or actionable suggestions.
  • Do not claim benchmark numbers unless measured evidence is provided in the input.

  • 禁止进行范围选择、安全、架构或语言/框架风格评审。仅聚焦性能维度。
  • 禁止在未提供具体位置或可执行建议的情况下给出结论。
  • 禁止在输入中未提供实测证据的情况下声称基准测试数据。

Self-Check

自我检查

  • Was only the performance dimension reviewed (no scope/security/architecture/style)?
  • Are complexity, query efficiency, I/O, memory, concurrency, caching, and load behavior covered where relevant?
  • Is each finding emitted with Location, Category=cognitive-performance, Severity, Title, Description, and optional Suggestion?
  • Are high-impact regression risks clearly distinguished from minor optimizations?

  • 是否仅评审了性能维度(未涉及范围/安全/架构/风格)?
  • 是否涵盖了复杂度、查询效率、I/O、内存、并发、缓存及负载行为(相关情况下)?
  • 每个问题发现是否都包含位置、类别=cognitive-performance、严重程度、标题、描述,以及可选的建议?
  • 是否明确区分了高影响的退化风险与次要优化建议?

Examples

示例

Example 1: N+1 query pattern

示例1:N+1查询模式

  • Input: Loop fetches child records per parent with one query per iteration.
  • Expected: Emit a major/critical finding for N+1 behavior; suggest batch query or join strategy. Category = cognitive-performance.
  • 输入:循环中针对每个父记录单独查询子记录,每次迭代执行一次查询。
  • 预期输出:针对N+1行为输出major或critical级别的问题发现;建议采用批量查询或关联策略。类别为cognitive-performance。

Example 2: Hot-path allocation churn

示例2:热点路径的内存分配周转

  • Input: Request handler repeatedly allocates large temporary buffers and serializes payload multiple times.
  • Expected: Emit a major finding for allocation pressure and latency impact; suggest reuse/pooling or single-pass transform. Category = cognitive-performance.
  • 输入:请求处理程序重复分配大型临时缓冲区,并多次序列化负载。
  • 预期输出:针对内存分配压力和延迟影响输出major级别的问题发现;建议采用复用/池化或单遍转换策略。类别为cognitive-performance。

Edge case: No clear performance risk in small formatting diff

边缘案例:小型格式调整diff中无明确性能风险

  • Input: Diff includes comments/renaming only, no behavioral changes.
  • Expected: Emit no findings or one suggestion-level note; do not invent optimization work. Category remains cognitive-performance for any emitted finding.

  • 输入:diff仅包含注释/重命名,无行为变更。
  • 预期输出:不输出任何问题发现,或输出一条建议级别的说明;不得凭空提出优化需求。若输出问题发现,类别仍为cognitive-performance。

Appendix: Output contract

附录:输出约定

Each finding MUST follow the standard findings format:
ElementRequirement
Location
path/to/file.ext
(optional line or range, or query/block identifier).
Category
cognitive-performance
.
Severity
critical
|
major
|
minor
|
suggestion
.
TitleShort one-line summary.
Description1-3 sentences.
SuggestionConcrete fix or improvement (optional).
Example:
markdown
- **Location**: `service/orders/handler.go:118`
- **Category**: cognitive-performance
- **Severity**: major
- **Title**: Per-item remote call inside request loop
- **Description**: The handler performs one downstream call per item, creating linear remote round-trips and latency growth.
- **Suggestion**: Batch requests or prefetch related data once per request; add timeout and bulk size guards.
每个问题发现必须遵循标准格式:
元素要求
Location(位置)
path/to/file.ext
(可选行号或范围,或查询/代码块标识)。
Category(类别)
cognitive-performance
Severity(严重程度)
critical
|
major
|
minor
|
suggestion
Title(标题)简短的单行摘要。
Description(描述)1-3句话。
Suggestion(建议)具体的修复或改进方案(可选)。
示例:
markdown
- **Location**: `service/orders/handler.go:118`
- **Category**: cognitive-performance
- **Severity**: major
- **Title**: Per-item remote call inside request loop
- **Description**: The handler performs one downstream call per item, creating linear remote round-trips and latency growth.
- **Suggestion**: Batch requests or prefetch related data once per request; add timeout and bulk size guards.