性能瓶颈诊断与修复

本条目介绍 性能瓶颈诊断与修复 的公开用途。DeepSkill 当前公开目录说明:“查找并修复性能瓶颈 — 包括 N+1 查询、缺失索引、同步瓶颈、缓存缺失等问题。适用于被问及“为什么这么慢”、“性能问题”、“优化此接口”或“N+1 查询”等场景。” 适用场景包括调试 API 与排查日志、写 SQL 取数。本页根据公开目录资料和固定版本的上游仓库整理,建议使用前核对该版本的环境、工具、权限及数据处理要求。Skillπ 提供站方用途介绍与原站链接;原始 SKILL.md 和附件仅在对应许可允许时开放。

仓库
jeremylongshore/tons-of-skills-marketplace

安装方式

先用 Prompt 核对来源,也可切换到安装命令或下载可用的安装包。

安装方式

用 AI 助手安装

复制提示词,让助手先核对固定版本和依赖。

查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "spine-perf":https://skillpi.com/zh/skills/deepskill-4de5ba4db2319b952ff93522c107173acdc8e853280194f74beb80084bfaad43。安装前核对上游来源和版本:https://github.com/jeremylongshore/tons-of-skills-marketplace/blob/6ea46b08dce892944db7c16f28d0b5308d402402/plugins/ai-agency/tonone/skills/spine-perf/SKILL.md。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。

此命令从 GitHub 来源仓库获取指定技能。运行前请先查看源文件。

运行工具
npx skills add https://github.com/jeremylongshore/tons-of-skills-marketplace/tree/6ea46b08dce892944db7c16f28d0b5308d402402/plugins/ai-agency/tonone/skills/spine-perf --skill spine-perf
许可协议: —

来源与配置

查看 GitHub 源码

jeremylongshore/tons-of-skills-marketplace固定提交 6ea46b08dce892944db7c16f28d0b5308d402402

配置方式待核实

请查看原始来源中的适用工具、依赖和权限要求。

安装实测待补充

本条目介绍 性能瓶颈诊断与修复 的公开用途。DeepSkill 当前公开目录说明:“查找并修复性能瓶颈 — 包括 N+1 查询、缺失索引、同步瓶颈、缓存缺失等问题。适用于被问及“为什么这么慢”、“性能问题”、“优化此接口”或“N+1 查询”等场景。” 适用场景包括调试 API 与排查日志、写 SQL 取数。本页根据公开目录资料和固定版本的上游仓库整理,建议使用前核对该版本的环境、工具、权限及数据处理要求。Skillπ 提供站方用途介绍与原站链接;原始 SKILL.md 和附件仅在对应许可允许时开放。

↓ 0 下载 ↗ 0 分享点击

文件浏览

在原站浏览文件 ↗

原始 SKILL.md

打开原文 ↗
---
name: spine-perf
description: Find and fix performance bottlenecks — N+1 queries, missing indexes, sync bottlenecks, caching gaps. Use when asked "why is this slow", "performance issue", "optimize this endpoint", or "N+1 queries".
allowed-tools: Read, Write, Edit, Bash, Glob, Grep, WebFetch, WebSearch, Task, TodoWrite, AskUserQuestion
version: 0.9.8
author: tonone-ai <hello@tonone.ai>
license: MIT
---

# Find and Fix Performance Bottlenecks

You are Spine — the backend engineer from the Engineering Team.

Follow the output format defined in docs/output-kit.md — 40-line CLI max, box-drawing skeleton, unified severity indicators, compressed prose.

## Steps

### Step 0: Run perf_scan.py

```bash
python team/spine/scripts/spine_agent/perf_scan.py [target] [--base-url http://...] [--paths /api/orders /api/users] [--skip-n1] [--skip-endpoints]
```

Run the real-tool layer first. This executes:

- **N+1 static analysis** — scans Python files for ORM query patterns inside loops, raw SQL in loops, string-formatted SQL, and related-field access without eager loading.
- **Endpoint profiler** — if `--base-url` and `--paths` are given, times each endpoint (3 warmup + 5 measured, reports p50/p95/p99). Flags endpoints >200ms (MEDIUM), >500ms (HIGH), >1000ms (CRITICAL).

The tool writes `.reports/spine-perf-<ts>.json` and exits 2 on CRITICAL/HIGH findings (CI gate).

Review the JSON report to seed the investigation in Steps 1-7 below.

### Step 1: Detect Environment

```bash
ls -a
```

Identify the framework and ORM: package.json (Express/Fastify + Prisma/TypeORM/Drizzle/Sequelize), pyproject.toml (FastAPI/Django + SQLAlchemy/Django ORM), go.mod (GORM, sqlx), Gemfile (Rails + ActiveRecord). Check for caching layers (Redis config), database config, and any existing performance tooling.

### Step 1: Read the Code Path

Read the specific code path the user is asking about. If they haven't specified, ask which endpoint or operation is slow. Trace the full request lifecycle:

- Route handler / controller
- Middleware that runs on this path
- Service / business logic layer
- Database queries (ORM calls, raw queries)
- External API calls
- Response serialization

### Step 2: Identify N+1 Queries

Look for patterns where:

- A list is fetched, then each item triggers an additional query (classic N+1)
- Associations/relations are accessed in a loop without eager loading
- ORM `.map()` / `.forEach()` / list comprehensions trigger lazy-loaded queries

For each N+1 found: explain the query pattern, show the fix (eager loading, join, subquery), and estimate the improvement (e.g., "N+1 with 100 items = 101 queries -> 1 query").

### Step 3: Check for Missing Indexes

Review the database queries in the code path and check:

- Are WHERE clause columns indexed?
- Are JOIN columns indexed?
- Are ORDER BY columns indexed?
- Are there composite indexes for multi-column queries?

Check migration files or schema definitions for existing indexes. Suggest specific indexes to add.

### Step 4: Identify Synchronous Bottlenecks

Flag operations that block the request unnecessarily:

- Synchronous external API calls that could be parallelized
- Sequential database queries that are independent and could run concurrently
- File I/O or computation on the request path that could be offloaded
- Missing connection pooling causing connection creation overhead

### Step 5: Check Caching Opportunities

Identify data that could be cached:

- Frequently read, rarely written data (user profiles, config, feature flags)
- Expensive computations or aggregations
- External API responses with acceptable staleness
- Database query results for hot paths

For each: suggest cache strategy (in-memory, Redis, HTTP cache headers), TTL, and invalidation approach.

### Step 6: Check Serialization Overhead

Flag:

- Over-fetching from database (SELECT \* when only 3 fields are needed)
- Serializing large nested objects when the client needs a subset
- Missing field selection or GraphQL-style projection
- Large payloads that could use pagination or streaming

### Step 7: Present the Report

Format as:

```
## Performance Analysis: [endpoint/operation]

### Issues Found

#### 1. [Issue name] — Estimated improvement: [Xms -> Yms] or [X queries -> Y queries]
**Why it's slow:** [explanation]
**Fix:**
[code snippet with the fix]

#### 2. [Issue name] — Estimated improvement: [X%]
**Why it's slow:** [explanation]
**Fix:**
[code snippet with the fix]

### Summary
| Issue              | Impact    | Effort | Fix               |
|-------------------|-----------|--------|-------------------|
| N+1 on /orders    | High      | Low    | Add eager loading |
| Missing index     | Medium    | Low    | Add index         |
| No caching        | High      | Medium | Add Redis cache   |
```

Prioritize by impact-to-effort ratio. Fix high-impact, low-effort issues first.

## Delivery

If output exceeds the 40-line CLI budget, invoke `/atlas-report` with the full findings. The HTML report is the output. CLI is the receipt — box header, one-line verdict, top 3 findings, and the report path. Never dump analysis to CLI.

当前收录版本

0.9.8

核对来源版本 ↗

质量评测

满分 100。前四项来自 DeepSkill 收录的质量报告。

场景价值85/100
评分依据

针对性能瓶颈(N+1 查询、索引缺失、缓存等)提供系统性分析流程

触发精准90/100
评分依据

触发词精准完整,覆盖多种变体(如“为什么这么慢”、“性能问题”、“N+1 查询”)

结构规范90/100
评分依据

Phase/步骤清晰(Step 0-7),有出口条件和端到端示例

执行可靠85/100
评分依据

工具来源明确(perf_scan.py),参数说明清晰

证据可验 (前四项均值)88/100
计算方式

取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。

权限与使用前检查

根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。

未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。

文档引用的域名或地址

这些地址可能用于文档链接或示例,不是已批准的联网清单。使用前核对实际目的地及发送的数据。

  • ...

本站展示提示不会授予权限。涉及文件改动、密钥、外部发送或费用时,仍由你使用的工具按需确认。

安全评级与访问范围

risk · 静态证据核验,不代表运行安全保证。

使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。

来源与使用声明 SkillPi 的部分技能资料来自公开来源或创作者提交。第三方内容的权利归各自权利人所有。安装或运行前,请查看原站的许可、权限要求和使用风险。

来源与使用

请按详情页的作者、原始来源和许可证核对使用条件,运行前检查技能需要的权限。目录收录不等于已验证安装或安全性。