# Hello Perf

> Hello Perf is an Agent Skill for development published in the hellowind777/helloagents repository on GitHub: a SKILL.md instruction file an AI agent can load to do this task.

优化性能、处理数据库查询、实现缓存、懒加载、分页、打包优化，或代码涉及大数据集循环、并发操作、内存管理时使用。

- Skill name: `hello-perf`
- Category: [Development](https://www.openparable.com/skill/development/1)
- Source: https://github.com/hellowind777/helloagents/blob/HEAD/skills/hello-perf/SKILL.md
- Repository: hellowind777/helloagents (638 GitHub stars when collected)

## SKILL.md

性能相关代码必须遵循以下规范。

## 编码前
先定位性能瓶颈（I/O / 计算 / 内存），再写代码。

## 查询优化
- 禁止 N+1 查询：使用 JOIN、批量加载、dataloader
- 大数据集必须分页，不一次加载全部
- 数据库索引覆盖常用查询条件
- 只查需要的字段（SELECT 具体列，不用 SELECT *）

## 缓存策略
- 读多写少的数据 → 缓存（内存/Redis）
- 设置合理的 TTL
- 缓存失效策略：写时失效 > 定时过期
- 防止缓存穿透（空值缓存）和雪崩（随机 TTL）

## 前端性能
- 代码分割 + 路由级懒加载
- 图片：WebP/AVIF、懒加载、srcset 响应式
- 声明 width/height 或 aspect-ratio 防止布局偏移
- 关键 CSS 内联，非关键 CSS 异步加载
- 50+ 项列表使用虚拟滚动

## 算法与并发
- 注意时间复杂度，禁止嵌套循环处理大数据集（O(n²)+）
- Map/Set 查找 O(1) vs Array.includes O(n)
- 批量操作优于逐条操作
- 高频事件（scroll/resize/input）使用 debounce/throttle

## 交付检查
- [ ] 无 N+1 查询
- [ ] 列表接口有分页
- [ ] 图片已优化（格式/懒加载/尺寸声明）
- [ ] 无嵌套循环处理大数据集

---

Source: https://www.openparable.com/skill/development/hello-perf (OpenParable). Cite the canonical URL above.
