114 lines
2.1 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
description: 性能优化师规范 - 检查性能问题
alwaysApply: false
---
# 性能优化师规范
## 一、数据库性能
### 检查项
- [ ] 是否存在 N+1 查询问题?
- [ ] 是否使用了合理的索引?
- [ ] 大数据量是否分页加载?
### N+1 查询示例
```typescript
// ❌ N+1 问题
const products = await prisma.product.findMany()
for (const product of products) {
const skus = await prisma.sKU.findMany({ where: { productId: product.id } })
}
// ✅ 正确:使用 include
const products = await prisma.product.findMany({
include: { skus: true }
})
```
---
## 二、前端性能
### 检查项
- [ ] 是否使用了 React Query 缓存?
- [ ] 大列表是否使用虚拟滚动?
- [ ] 图片是否懒加载?
### React Query 缓存
```typescript
const { data } = useQuery({
queryKey: ['products', filters],
queryFn: () => fetchProducts(filters),
staleTime: 5 * 60 * 1000, // 5分钟
})
```
---
## 三、3D 性能
### 检查项
- [ ] 模型是否使用 LOD 策略?
- [ ] 组件卸载时是否清理资源?
- [ ] 是否避免内存泄漏?
### 内存泄漏检查
- 事件监听器是否移除?
- 定时器是否清除?
- GSAP 动画是否停止?
- geometry/material/texture 是否释放?
---
## 四、性能监控
### 请求计时
```typescript
const result = await timeAsync('product.import', async () => {
// 耗时操作
})
```
### 日志规范
```typescript
logger.info('Product created', {
productId: product.id,
userId: ctx.user.id,
duration: elapsed
})
```
---
## 五、性能检查清单
| 类别 | 检查项 |
|------|--------|
| 数据库 | N+1 查询、索引、分页 |
| 前端 | React Query 缓存、虚拟滚动、懒加载 |
| 3D | LOD、资源清理、内存泄漏 |
| 监控 | 请求计时、日志记录 |
---
## 六、审查报告格式
```
## 性能审查结果
### 通过项 ✅
- 使用了 React Query 缓存
- 使用了分页加载
### 优化建议 ⚠️
- 第 X 行存在 N+1 查询
→ 修复:使用 include 预加载关联数据
### 严重问题 ❌
- 组件卸载时未清理资源
→ 修复:添加 dispose() 方法
### 评分:X/10
```