codeprobe-performance
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseStandalone Mode
独立模式
If invoked directly (not via the orchestrator), you must first:
- Read for the output contract, execution modes, and constraints.
../codeprobe/shared-preamble.md - Load applicable reference files from based on the project's tech stack.
../codeprobe/references/ - Default to mode unless the user specifies otherwise.
full
如果直接调用(不通过编排器),您必须首先:
- 阅读以了解输出协议、执行模式和约束条件。
../codeprobe/shared-preamble.md - 根据项目技术栈加载中的适用参考文件。
../codeprobe/references/ - 除非用户另行指定,否则默认使用模式。
full
Performance & Scalability Auditor
性能与可扩展性审计器
Domain Scope
领域范围
This sub-skill detects performance and scalability issues across these categories:
- N+1 Queries — Lazy-loading relationships inside loops
- Missing Indexes — WHERE/ORDER BY on non-indexed columns
- Unbounded Queries — Model::all() without pagination/limit
- Memory — Loading entire files into memory, array accumulation in loops
- Caching — Repeated identical queries, missing TTL, stale cache after writes
- Algorithmic Efficiency — O(n^2) in hot paths, nested loops, sorting in loops
- Concurrency — Race conditions, non-idempotent queue jobs, shared mutable state
- Frontend Performance — Unnecessary re-renders, bundle size, missing lazy loading
该子技能检测以下类别的性能与可扩展性问题:
- N+1 查询 — 循环内延迟加载关联关系
- 缺失索引 — 在未索引列上使用WHERE/ORDER BY
- 无界查询 — Model::all()未使用分页/限制
- 内存问题 — 将整个文件加载到内存中、循环内数组累积
- 缓存问题 — 重复执行相同查询、缺失TTL、写入后缓存过期
- 算法效率 — 热点路径中的O(n^2)复杂度、嵌套循环、循环内排序
- 并发问题 — 竞态条件、非幂等队列任务、共享可变状态
- 前端性能 — 不必要的重渲染、包体积过大、缺失懒加载
What It Does NOT Flag
不标记的内容
- Premature optimization in non-hot-path code — proportional design matters. A utility function called once at startup doesn't need the same optimization as a request handler.
- Development-only debug queries — queries in seeders, dev-only commands, or debug endpoints.
- Batch processing scripts — scripts intentionally designed to process everything (migrations, data backfills) where unbounded queries may be appropriate.
- O(n^2) on small bounded collections (<100 items) — nested loops on small known-size arrays are fine.
- Frontend SSR/build-time code — server components and build scripts have different performance profiles than client-side code.
- 非热点路径中的过早优化 — 设计需与场景匹配。启动时仅调用一次的工具函数无需与请求处理函数采用相同的优化标准。
- 仅开发环境使用的调试查询 — 种子文件、仅开发环境命令或调试端点中的查询。
- 批处理脚本 — 专门设计用于处理全部数据的脚本(如迁移、数据回填),此类场景中无界查询可能是合理的。
- 小型有限集合(<100条数据)上的O(n^2)操作 — 在已知大小的小型数组上使用嵌套循环是可行的。
- 前端SSR/构建时代码 — 服务端组件和构建脚本的性能特征与客户端代码不同。
Detection Instructions
检测说明
N+1 Queries
N+1 查询
| ID Prefix | What to Detect | How to Detect | Severity |
|---|---|---|---|
| Eloquent relationship access inside loop without eager loading | Search for | Critical |
| Any ORM lazy-loading inside iteration | Look for patterns where a database query is implicitly triggered inside a loop: Django querysets accessed per-iteration, SQLAlchemy lazy loads, Prisma relation access in | Critical |
| Template/view triggering queries | Blade templates, Jinja2 templates, or React components calling relationship properties that trigger queries during rendering. | Major |
| ID 前缀 | 检测内容 | 检测方式 | 严重程度 |
|---|---|---|---|
| 循环内访问Eloquent关联关系但未使用预加载 | 搜索遍历集合的 | 严重 |
| 迭代过程中任何ORM延迟加载 | 查找循环内隐式触发数据库查询的模式:Django查询集逐次访问、SQLAlchemy延迟加载、Prisma在 | 严重 |
| 模板/视图触发查询 | Blade模板、Jinja2模板或React组件在渲染时调用关联属性从而触发查询。 | 主要 |
Missing Indexes
缺失索引
| ID Prefix | What to Detect | How to Detect | Severity |
|---|---|---|---|
| WHERE/ORDER BY on non-indexed columns | Cross-reference query conditions ( | Major |
| Foreign keys without indexes | Check migration files for | Minor |
| Composite queries needing compound indexes | Multiple | Minor |
| ID 前缀 | 检测内容 | 检测方式 | 严重程度 |
|---|---|---|---|
| 在未索引列上使用WHERE/ORDER BY | 将查询条件( | 主要 |
| 外键未设置索引 | 检查迁移文件中的 | 次要 |
| 需要复合索引的复合查询 | 同一查询中对不同列使用多个 | 次要 |
Unbounded Queries
无界查询
| ID Prefix | What to Detect | How to Detect | Severity |
|---|---|---|---|
| | Search for | Major |
| Missing cursor/chunk for large dataset processing | Operations that | Major |
| ID 前缀 | 检测内容 | 检测方式 | 严重程度 |
|---|---|---|---|
| | 搜索 | 主要 |
| 处理大型数据集时缺失游标/分块 | 使用 | 主要 |
Memory
内存问题
| ID Prefix | What to Detect | How to Detect | Severity |
|---|---|---|---|
| Loading entire files into memory | | Major |
| Array accumulation in loops | Arrays that grow inside loops without bounds or cleanup — collecting results in memory that could be streamed or yielded. | Minor |
| Large collections instead of generators | Returning full arrays/lists where generators ( | Minor |
| ID 前缀 | 检测内容 | 检测方式 | 严重程度 |
|---|---|---|---|
| 将整个文件加载到内存中 | 对用户上传文件或大文件使用 | 主要 |
| 循环内数组累积 | 循环内无限制增长或未清理的数组——在内存中收集结果,而这些结果本可以流式传输或生成。 | 次要 |
| 使用大型集合而非生成器 | 返回完整数组/列表,而对于大型数据集,使用生成器( | 次要 |
Caching
缓存问题
| ID Prefix | What to Detect | How to Detect | Severity |
|---|---|---|---|
| Repeated identical queries in same request | Same query pattern executed multiple times within a single request/function call without caching the result. | Minor |
| Cache without TTL | | Minor |
| Cache not invalidated after writes | Write operations (create/update/delete) that don't clear or update related cache entries. Stale cache served after mutation. | Major |
| ID 前缀 | 检测内容 | 检测方式 | 严重程度 |
|---|---|---|---|
| 同一请求中重复执行相同查询 | 同一请求/函数调用中多次执行相同查询模式但未缓存结果。 | 次要 |
| 缓存未设置TTL | | 次要 |
| 写入后未失效缓存 | 写入操作(创建/更新/删除)未清除或更新相关缓存条目。数据变更后仍提供过期缓存。 | 主要 |
Algorithmic Efficiency
算法效率
| ID Prefix | What to Detect | How to Detect | Severity |
|---|---|---|---|
| O(n^2) or worse in hot paths | Nested loops iterating over the same or related collections. | Major |
| Sorting inside loops | | Major |
| Hashmap-replaceable linear search | | Minor |
| ID 前缀 | 检测内容 | 检测方式 | 严重程度 |
|---|---|---|---|
| 热点路径中的O(n^2)或更差复杂度 | 遍历相同或相关集合的嵌套循环。循环内使用 | 主要 |
| 循环内排序 | 循环体中调用 | 主要 |
| 可替换为哈希表的线性搜索 | 对同一数组重复使用 | 次要 |
Concurrency
并发问题
| ID Prefix | What to Detect | How to Detect | Severity |
|---|---|---|---|
| Race conditions in read-modify-write | Patterns that read a value, modify it, and write back without locking: incrementing counters, updating balances, toggling flags in concurrent contexts. | Critical |
| Queue jobs without idempotency | Queue/job handlers that don't check for duplicate execution. Jobs that create resources without checking if already created. Missing unique constraints on job-created data. | Major |
| Shared mutable state in async contexts | Global/module-level mutable variables accessed in async handlers, request-scoped data stored in module scope. | Major |
| ID 前缀 | 检测内容 | 检测方式 | 严重程度 |
|---|---|---|---|
| 读取-修改-写入中的竞态条件 | 读取值、修改值并写回但未加锁的模式:并发场景下的计数器递增、余额更新、标志位切换。 | 严重 |
| 非幂等队列任务 | 未检查重复执行的队列/任务处理器。创建资源时未检查是否已存在的任务。任务创建的数据缺失唯一约束。 | 主要 |
| 异步上下文内的共享可变状态 | 异步处理器中访问的全局/模块级可变变量,存储在模块作用域中的请求级数据。 | 主要 |
Frontend Performance
前端性能
| ID Prefix | What to Detect | How to Detect | Severity |
|---|---|---|---|
| Unnecessary re-renders | Missing | Minor |
| Large bundle imports | | Minor |
| Missing lazy loading | No | Minor |
| ID 前缀 | 检测内容 | 检测方式 | 严重程度 |
|---|---|---|---|
| 不必要的重渲染 | 昂贵计算或接收新对象/数组引用的组件未使用 | 次要 |
| 大体积包导入 | | 次要 |
| 缺失懒加载 | 路由级代码拆分未使用 | 次要 |
Optional Script Integration
可选脚本集成
When output is available (run by the orchestrator during or ), use it to identify high-complexity functions as performance hot-spot candidates. Functions rated "high" or "very_high" that also appear in hot paths (request handlers, loop bodies, frequently-called utilities) are strong signals for algorithmic efficiency findings.
scripts/complexity_scorer.py/codeprobe health/codeprobe audit当的输出可用时(由编排器在或期间运行),使用它识别高复杂度函数作为性能热点候选。被评为“high”或“very_high”且出现在热点路径(请求处理器、循环体、频繁调用的工具函数)中的函数是算法效率问题的强烈信号。
scripts/complexity_scorer.py/codeprobe health/codeprobe auditID Prefix & Fix Prompt Examples
ID前缀与修复提示示例
All findings use the prefix, numbered sequentially: , , etc.
PERF-PERF-001PERF-002所有检测结果使用前缀,并按顺序编号:、等。
PERF-PERF-001PERF-002Fix Prompt Examples
修复提示示例
- "In (line 22), add
OrderController@indexto the->with('items', 'customer')call to fix the N+1 problem — currently loading 2 relations lazily inside the Blade loop atOrder::query()."orders/index.blade.php:15 - "Replace at line 30 of
Product::all()withCatalogService.phporProduct::query()->paginate(25)if processing all records. The current query loads all products into memory."Product::cursor() - "In (lines 45-60), the nested loop iterating
ReportGenerator@aggregateinside$ordersis O(n*m). Build a lookup hashmap before the outer loop:$customers."$ordersByCustomerId = collect($orders)->groupBy('customer_id') - "Replace at line 3 of
import _ from 'lodash'with specific imports:src/utils/helpers.tsto reduce bundle size."import debounce from 'lodash/debounce'
- "在(第22行),向
OrderController@index调用添加Order::query()以修复N+1问题——当前在->with('items', 'customer')的Blade循环内延迟加载2个关联关系。"orders/index.blade.php:15 - "将第30行的
CatalogService.php替换为Product::all();如果需要处理所有记录,可使用Product::query()->paginate(25)。当前查询会将所有产品加载到内存中。"Product::cursor() - "在(第45-60行),嵌套循环在
ReportGenerator@aggregate内遍历$customers的复杂度为O(n*m)。在外层循环前构建查找哈希表:$orders。"$ordersByCustomerId = collect($orders)->groupBy('customer_id') - "将第3行的
src/utils/helpers.ts替换为按需导入:import _ from 'lodash'以减小包体积。"import debounce from 'lodash/debounce'