plugins/code-review/skills/performance-review/SKILL.md
性能瓶颈定位、资源评估与优化建议能力。 当用户说"性能分析"、"性能优化"、"性能瓶颈"、"响应慢"、"内存泄漏"、"CPU占用高"、"优化代码"、"基准测试"、"负载测试"时使用此技能。 支持算法复杂度分析(时间/空间复杂度)、资源使用评估(CPU/内存/I/O)、并发性能检查、数据库查询优化(N+1问题、索引分析)。 输出包含性能报告、优化策略和代码对比示例。
npx skillsauth add protagonistss/ithinku-plugins performance-reviewInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
专业的性能分析技能,能够识别代码性能瓶颈、评估运行效率并提供优化建议。
Performance Review 技能提供深度的代码性能分析能力,包括算法复杂度分析、资源使用评估、并发性能检查和数据库查询优化。
# 分析性能瓶颈
/performance-review src/algorithms/
# 专注特定性能指标
/performance-review src/services/ --metrics cpu,memory
# 生成优化报告
/performance-review src/ --format report --benchmark
# 深度性能分析
/performance-review src/data-processing.js --depth deep
// 性能问题代码
function findDuplicates(arr) {
const duplicates = [];
for (let i = 0; i < arr.length; i++) {
for (let j = i + 1; j < arr.length; j++) {
if (arr[i] === arr[j]) {
duplicates.push(arr[i]);
}
}
}
return duplicates;
}
// 优化方案 O(n)
function findDuplicatesOptimized(arr) {
const seen = new Set();
const duplicates = new Set();
for (const item of arr) {
if (seen.has(item)) {
duplicates.add(item);
} else {
seen.add(item);
}
}
return Array.from(duplicates);
}
// 性能问题代码
function updateList(items) {
const list = document.getElementById('list');
list.innerHTML = ''; // 清空列表
items.forEach(item => {
const li = document.createElement('li');
li.textContent = item;
list.appendChild(li); // 频繁DOM操作
});
}
// 优化方案
function updateListOptimized(items) {
const list = document.getElementById('list');
const fragment = document.createDocumentFragment();
items.forEach(item => {
const li = document.createElement('li');
li.textContent = item;
fragment.appendChild(li);
});
list.innerHTML = '';
list.appendChild(fragment); // 一次性DOM操作
}
// 性能问题代码 - N+1查询问题
async function getUsersWithPosts() {
const users = await db.query('SELECT * FROM users');
for (const user of users) {
user.posts = await db.query(
'SELECT * FROM posts WHERE user_id = ?',
[user.id]
);
}
return users;
}
// 优化方案 - 单次查询
async function getUsersWithPostsOptimized() {
const result = await db.query(`
SELECT
u.*,
p.id as post_id,
p.title,
p.content
FROM users u
LEFT JOIN posts p ON u.id = p.user_id
ORDER BY u.id, p.id
`);
// 转换为嵌套结构
const usersMap = new Map();
for (const row of result) {
if (!usersMap.has(row.id)) {
usersMap.set(row.id, {
id: row.id,
name: row.name,
email: row.email,
posts: []
});
}
if (row.post_id) {
usersMap.get(row.id).posts.push({
id: row.post_id,
title: row.title,
content: row.content
});
}
}
return Array.from(usersMap.values());
}
const Benchmark = require('benchmark');
const suite = new Benchmark.Suite;
// 添加测试用例
suite
.add('Original', function() {
findDuplicates(largeArray);
})
.add('Optimized', function() {
findDuplicatesOptimized(largeArray);
})
.on('cycle', function(event) {
console.log(String(event.target));
})
.on('complete', function() {
console.log('Fastest is ' + this.filter('fastest').map('name'));
})
.run({ 'async': true });
// 使用Artillery进行负载测试
// artillery.yml
config:
target: 'http://localhost:3000'
phases:
- duration: 60
arrivalRate: 10
- duration: 120
arrivalRate: 50
- duration: 60
arrivalRate: 100
scenarios:
- name: "Load test API"
requests:
- get:
url: "/api/users"
- post:
url: "/api/users"
json:
name: "Test User"
email: "[email protected]"
// 性能监控中间件
const performanceMonitor = (req, res, next) => {
const start = Date.now();
res.on('finish', () => {
const duration = Date.now() - start;
// 记录性能指标
console.log(`${req.method} ${req.path} - ${duration}ms`);
// 发送到监控系统
sendMetrics({
endpoint: req.path,
method: req.method,
duration: duration,
statusCode: res.statusCode,
timestamp: new Date().toISOString()
});
});
next();
};
// 内存使用监控
const memoryMonitor = () => {
const used = process.memoryUsage();
console.log('Memory Usage:');
for (let key in used) {
console.log(`${key}: ${Math.round(used[key] / 1024 / 1024)} MB`);
}
};
// 定期检查
setInterval(memoryMonitor, 30000);
# 性能分析报告
## 基本信息
- **分析范围**: 用户管理模块
- **技术栈**: Node.js, Express, MongoDB
- **数据规模**: 10万用户,100万帖子
- **测试环境**: AWS EC2 t3.large
- **分析时间**: 2024-01-15 14:00:00
## 性能概览
- **平均响应时间**: 245ms (目标: < 200ms)
- **95百分位响应时间**: 892ms (目标: < 500ms)
- **吞吐量**: 450 RPS (目标: > 1000 RPS)
- **CPU使用率**: 78% (目标: < 70%)
- **内存使用**: 1.8GB (目标: < 2GB)
- **性能评分**: 6.2/10
## 🔍 性能瓶颈分析
### 1. 数据库查询优化 (预计提升60%)
**问题**: N+1查询问题
**位置**: userService.js:45-62
**影响**: 用户列表加载缓慢
**当前实现**:
```javascript
// 执行101次数据库查询 (1次用户查询 + 100次帖子查询)
const users = await User.find();
for (const user of users) {
user.posts = await Post.find({ userId: user.id });
}
优化方案:
// 使用JOIN查询,只需1次数据库查询
const users = await User.aggregate([
{
$lookup: {
from: 'posts',
localField: '_id',
foreignField: 'userId',
as: 'posts'
}
}
]);
预期效果:
问题: 缺少有效的缓存机制 建议: 实施Redis缓存
缓存策略:
const cache = require('redis').createClient();
async function getCachedUser(userId) {
// 尝试从缓存获取
const cached = await cache.get(`user:${userId}`);
if (cached) {
return JSON.parse(cached);
}
// 从数据库获取
const user = await User.findById(userId);
// 存入缓存 (30分钟过期)
await cache.setex(`user:${userId}`, 1800, JSON.stringify(user));
return user;
}
问题: 用户搜索算法复杂度为O(n²) 优化: 使用倒排索引
优化前后对比:
| 操作 | 优化前 | 优化后 | 提升 | |------|--------|--------|------| | 用户列表 | 892ms | 245ms | 72% | | 用户搜索 | 2300ms | 340ms | 85% | | 用户创建 | 120ms | 85ms | 29% | | 用户更新 | 95ms | 72ms | 24% |
并发用户: 1000 测试时长: 10分钟
| 指标 | 优化前 | 优化后 | 改善 | |------|--------|--------|------| | 平均响应时间 | 1.2s | 0.3s | 75% | | 错误率 | 5.2% | 0.1% | 98% | | 吞吐量 | 234 RPS | 892 RPS | 281% |
数据库查询优化 (2天)
基础缓存 (3天)
搜索引擎优化 (5天)
CDN集成 (2天)
alerts:
- name: "High Response Time"
condition: "avg_response_time > 500ms"
duration: "5m"
- name: "High CPU Usage"
condition: "cpu_usage > 80%"
duration: "10m"
- name: "Low Cache Hit Rate"
condition: "cache_hit_rate < 60%"
duration: "15m"
通过系统的性能分析和优化,可以显著提升应用程序的响应速度和用户体验。
development
Vue 3 开发最佳实践指南 - Composition API、Script Setup、Pinia、TypeScript 集成及性能优化。 当用户说"Vue 3组件"、"Composition API"、"script setup"、"Pinia"、"Vue 3项目"、"ref reactive"、"defineProps defineEmits"、"Composable"、"Vue 3优化"时使用此技能。 涵盖:Script Setup 与 Composition API、响应式数据选择(ref vs reactive)、组件通信(Props/Emits/v-model/Slots)、Composables 设计模式、Pinia Setup Store、性能优化(v-memo、shallowRef、KeepAlive)。 提供 TypeScript 代码示例、反模式对照表、迁移指南和示例文件引用。
development
Vue 2 维护与开发最佳实践指南 - Options API、Vuex 及向 Vue 3 迁移准备。 当用户说"Vue 2组件"、"Options API"、"Vuex"、"Vue 2项目"、"Vue 2迁移"、"Vue mixin"、"Vue 2最佳实践"时使用此技能。 涵盖:Options API 规范(选项顺序、props 验证)、Vuex 模块化(namespaced modules)、逻辑复用(避免 mixin,使用工具函数)、迁移准备(停止使用 Filters、引入 Composition API 插件)。 提供 Vue 2 代码示例、反模式警告和迁移建议。
development
核心设计能力 - 提供配色、布局、组件样式生成及反模式检查。 当用户说"设计UI"、"生成样式"、"页面布局"、"CSS样式"、"组件设计"、"配色方案"、"设计系统"、"前端样式"、"响应式设计"、"动画效果"时使用此技能。 支持多种设计风格:Neo-Brutalism、Glassmorphism、Editorial、Cyberpunk。 提供配色方案、布局生成、组件样式、微交互动效、响应式网格。拒绝"AI廉价感",追求大胆、独特、细节丰富的设计。 重要特性:提供反模式检查,避免泛滥的渐变、无聊的阴影、默认圆角等平庸设计。
content-media
无障碍设计审查与修复能力。 当用户说"无障碍"、"a11y"、"WCAG"、"键盘导航"、"屏幕阅读器"、"颜色对比度"、"ARIA"、"可访问性"、"辅助功能"、"盲人友好"时使用此技能。 基于 WCAG 2.1 标准,检测图片 Alt 文本缺失、表单 Label 关联、键盘可访问性、颜色对比度不足、ARIA 属性误用等问题。 提供修复代码示例:语义化标签、焦点管理、焦点陷阱、屏幕阅读器支持。输出合规性检查报告和修复建议。