optimize
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseOptimize
优化
Reduce waste and improve efficiency across four dimensions.
从四个维度减少冗余,提升效率。
Choose Your Path
选择优化路径
Speed → Pages slow, APIs timeout, sluggish UX
Code → Bloated codebase, unused files, redundant components
Database → Orphaned data, unused fields/tables, slow queries
Dependencies → Package bloat, large bundles, outdated libraries
速度 → 页面加载慢、API超时、用户体验卡顿
代码 → 代码库臃肿、存在未使用文件、冗余组件
数据库 → 孤立数据、未使用字段/表、查询缓慢
依赖项 → 包冗余、打包体积过大、库版本过时
When to Optimize
何时进行优化
Optimize when:
- App feels slow (Speed)
- Codebase has grown significantly (Code)
- Database has accumulated cruft (Database)
- Bundle size is large or security warnings appear (Dependencies)
Don't optimize when:
- Building MVP
- < 100 users
- Everything works fine
Rule: Make it work, then make it lean.
适合优化的场景:
- 应用运行缓慢(速度维度)
- 代码库规模显著增长(代码维度)
- 数据库积累了冗余数据(数据库维度)
- 打包体积过大或出现安全警告(依赖项维度)
不适合优化的场景:
- 开发MVP阶段
- 用户量不足100人
- 所有功能运行正常
原则: 先确保功能可用,再优化精简。
Speed Optimization
速度优化
Make your app fast and responsive.
让你的应用快速响应。
Targets
优化指标
| Metric | Good | Bad |
|---|---|---|
| Page load | < 3s | > 5s |
| API response | < 500ms | > 1s |
| Time to interactive | < 5s | > 8s |
| Database query | < 100ms | > 500ms |
| 指标 | 良好标准 | 不良标准 |
|---|---|---|
| 页面加载 | < 3秒 | > 5秒 |
| API响应 | < 500毫秒 | > 1秒 |
| 可交互时间 | < 5秒 | > 8秒 |
| 数据库查询 | < 100毫秒 | > 500毫秒 |
AUDIT
审计
Identify what's slow.
Tell AI:
Audit app performance:
- Measure page load times
- Log API response times
- Identify slow database queries
- Check bundle size
Report findings with specific numbers.Quick manual check:
- Chrome DevTools → Network tab → Reload → Check "Load" time
- Chrome DevTools → Network tab → Click action → Check API time
定位性能瓶颈。
告知AI:
Audit app performance:
- Measure page load times
- Log API response times
- Identify slow database queries
- Check bundle size
Report findings with specific numbers.快速手动检查:
- Chrome DevTools → 网络面板 → 重新加载 → 查看「加载」时间
- Chrome DevTools → 网络面板 → 执行操作 → 查看API响应时间
CLEAN
清理
Fix identified issues.
Tell AI:
Optimize these performance issues:
[paste audit findings]
Apply fixes:
- Add caching for slow API calls
- Add database indexes for slow queries
- Optimize/lazy-load images
- Code split large bundles修复已定位的问题。
告知AI:
Optimize these performance issues:
[paste audit findings]
Apply fixes:
- Add caching for slow API calls
- Add database indexes for slow queries
- Optimize/lazy-load images
- Code split large bundlesPREVENT
预防
Stop future slowdowns.
Tell AI:
Add performance monitoring:
- Log API calls > 500ms
- Log database queries > 100ms
- Alert on page load > 3s
- Track bundle size in CISee PERFORMANCE-CHECKS.md for testing methods.
See OPTIMIZATION-PROMPTS.md for specific patterns.
避免未来出现性能下降。
告知AI:
Add performance monitoring:
- Log API calls > 500ms
- Log database queries > 100ms
- Alert on page load > 3s
- Track bundle size in CI查看 PERFORMANCE-CHECKS.md 获取测试方法。
查看 OPTIMIZATION-PROMPTS.md 获取具体模板。
Code Optimization
代码优化
Remove unused code and reduce complexity.
移除未使用代码,降低复杂度。
Signs You Need This
需要优化的信号
- Files you don't recognize
- Components that aren't used anywhere
- Multiple versions of similar code
- "I'm afraid to delete this"
- 存在你不熟悉的文件
- 组件未在任何地方使用
- 存在多版类似代码
- 「我不敢删除这个」
AUDIT
审计
Find unused code.
Tell AI:
Audit codebase for unused code:
- Find components not imported anywhere
- Find functions never called
- Find files not referenced
- Find duplicate/similar code
- Find commented-out code blocks
List each with file path and last modified date.What to look for:
- Dead components (created during iteration, never used)
- Orphaned utilities (helper functions nothing calls)
- Abandoned features (half-built, never finished)
- Copy-paste duplication (same logic in multiple places)
找出未使用代码。
告知AI:
Audit codebase for unused code:
- Find components not imported anywhere
- Find functions never called
- Find files not referenced
- Find duplicate/similar code
- Find commented-out code blocks
List each with file path and last modified date.检查重点:
- 废弃组件(迭代过程中创建但从未使用)
- 孤立工具函数(无任何调用的辅助函数)
- 未完成功能(开发到一半被放弃)
- 复制粘贴的重复代码(相同逻辑出现在多个位置)
CLEAN
清理
Remove identified waste.
Tell AI:
Remove this unused code:
[paste audit findings]
Before deleting:
- Verify nothing imports/calls it
- Check git history for context
- Remove related tests if any
After deleting:
- Run build to verify no breaks
- Run tests to verify no breaksSafety rule: If unsure, comment out first and test. Delete after confirming nothing breaks.
移除已发现的冗余代码。
告知AI:
Remove this unused code:
[paste audit findings]
Before deleting:
- Verify nothing imports/calls it
- Check git history for context
- Remove related tests if any
After deleting:
- Run build to verify no breaks
- Run tests to verify no breaks安全原则: 若不确定,先注释代码并测试,确认无影响后再删除。
PREVENT
预防
Stop code accumulation.
Tell AI:
Set up code hygiene practices:
- Add ESLint rule for unused imports
- Add ESLint rule for unused variables
- Configure IDE to highlight unused code
- Add CI check for unused exportsSee CODE.md for detailed patterns.
避免代码冗余积累。
告知AI:
Set up code hygiene practices:
- Add ESLint rule for unused imports
- Add ESLint rule for unused variables
- Configure IDE to highlight unused code
- Add CI check for unused exports查看 CODE.md 获取详细模板。
Database Optimization
数据库优化
Clean up data schema and orphaned records.
清理数据架构与孤立记录。
Signs You Need This
需要优化的信号
- Tables you don't recognize
- Fields that are always null
- Queries getting slower over time
- "What is this table for?"
- 存在你不熟悉的表
- 字段始终为null
- 查询速度随时间变慢
- 「这个表是做什么的?」
AUDIT
审计
Find database waste.
Tell AI:
Audit database for cleanup opportunities:
- Tables with no recent reads/writes
- Columns that are always NULL or empty
- Orphaned records (foreign keys pointing to deleted rows)
- Duplicate data across tables
- Missing indexes on frequently queried fields
List each with table name, row count, and last access if available.What to look for:
- Abandoned feature tables (feature removed, table remains)
- Legacy columns (renamed but old column kept)
- Orphaned records (user deleted, their data remains)
- Redundant data (same info stored multiple places)
找出数据库冗余。
告知AI:
Audit database for cleanup opportunities:
- Tables with no recent reads/writes
- Columns that are always NULL or empty
- Orphaned records (foreign keys pointing to deleted rows)
- Duplicate data across tables
- Missing indexes on frequently queried fields
List each with table name, row count, and last access if available.检查重点:
- 废弃功能表(功能已移除但表保留)
- 遗留字段(已重命名但旧字段未删除)
- 孤立记录(用户已删除但其数据保留)
- 冗余数据(相同信息存储在多个位置)
CLEAN
清理
Remove identified waste.
Tell AI:
Clean up database:
[paste audit findings]
Before removing:
- Backup affected tables
- Verify no code references removed tables/columns
- Check for foreign key constraints
Migration steps:
- Create migration to drop unused columns
- Create migration to drop unused tables
- Create script to delete orphaned records
- Add missing indexesSafety rule: Always backup before schema changes. Test on staging first.
移除已发现的冗余内容。
告知AI:
Clean up database:
[paste audit findings]
Before removing:
- Backup affected tables
- Verify no code references removed tables/columns
- Check for foreign key constraints
Migration steps:
- Create migration to drop unused columns
- Create migration to drop unused tables
- Create script to delete orphaned records
- Add missing indexes安全原则: 更改架构前务必备份,先在 staging 环境测试。
PREVENT
预防
Stop data accumulation.
Tell AI:
Set up database hygiene:
- Add ON DELETE CASCADE for dependent records
- Add NOT NULL constraints where appropriate
- Create cleanup job for soft-deleted records (>90 days)
- Add monitoring for table size growthSee DATABASE.md for detailed patterns.
避免数据冗余积累。
告知AI:
Set up database hygiene:
- Add ON DELETE CASCADE for dependent records
- Add NOT NULL constraints where appropriate
- Create cleanup job for soft-deleted records (>90 days)
- Add monitoring for table size growth查看 DATABASE.md 获取详细模板。
Dependencies Optimization
依赖项优化
Reduce package bloat and bundle size.
减少包冗余与打包体积。
Signs You Need This
需要优化的信号
- takes forever
npm install - Bundle size > 500KB
- Security vulnerability warnings
- "What does this package do?"
- 耗时极长
npm install - 打包体积 > 500KB
- 出现安全漏洞警告
- 「这个包是做什么的?」
AUDIT
审计
Find dependency waste.
Tell AI:
Audit dependencies:
- List packages not imported anywhere in code
- List packages with security vulnerabilities
- List packages with major version updates available
- Analyze bundle size by package
- Find duplicate packages (different versions of same thing)
Report: package name, size impact, last used, and recommendation.Quick manual check:
bash
undefined找出依赖项冗余。
告知AI:
Audit dependencies:
- List packages not imported anywhere in code
- List packages with security vulnerabilities
- List packages with major version updates available
- Analyze bundle size by package
- Find duplicate packages (different versions of same thing)
Report: package name, size impact, last used, and recommendation.快速手动检查:
bash
undefinedCheck bundle size
Check bundle size
npm run build
npm run build
Check for unused packages
Check for unused packages
npx depcheck
npx depcheck
Check for vulnerabilities
Check for vulnerabilities
npm audit
npm audit
Check for outdated packages
Check for outdated packages
npm outdated
undefinednpm outdated
undefinedCLEAN
清理
Remove identified waste.
Tell AI:
Clean up dependencies:
[paste audit findings]
Steps:
- Remove unused packages from package.json
- Update packages with security vulnerabilities
- Replace heavy packages with lighter alternatives
- Remove duplicate package versions
After changes:
- Delete node_modules and package-lock.json
- Fresh npm install
- Run build and testsCommon replacements:
| Heavy | Light Alternative |
|---|---|
| moment.js | date-fns or dayjs |
| lodash (full) | lodash-es (tree-shakeable) |
| axios | fetch (built-in) |
移除已发现的冗余依赖。
告知AI:
Clean up dependencies:
[paste audit findings]
Steps:
- Remove unused packages from package.json
- Update packages with security vulnerabilities
- Replace heavy packages with lighter alternatives
- Remove duplicate package versions
After changes:
- Delete node_modules and package-lock.json
- Fresh npm install
- Run build and tests常见替代方案:
| 重型包 | 轻量替代包 |
|---|---|
| moment.js | date-fns 或 dayjs |
| lodash (完整版) | lodash-es (支持 tree-shaking) |
| axios | fetch (内置API) |
PREVENT
预防
Stop dependency bloat.
Tell AI:
Set up dependency hygiene:
- Add bundle size check to CI (fail if > X KB)
- Add npm audit to CI pipeline
- Configure Dependabot for security updates
- Add depcheck to pre-commit hookSee DEPENDENCIES.md for detailed patterns.
避免依赖项冗余积累。
告知AI:
Set up dependency hygiene:
- Add bundle size check to CI (fail if > X KB)
- Add npm audit to CI pipeline
- Configure Dependabot for security updates
- Add depcheck to pre-commit hook查看 DEPENDENCIES.md 获取详细模板。
Optimization Priority
优化优先级
When everything needs work:
- Speed - Users feel this immediately
- Dependencies - Security vulnerabilities are urgent
- Database - Affects long-term performance
- Code - Affects maintainability, not users
Quick wins per category:
| Category | Quick Win |
|---|---|
| Speed | Add caching to slowest API endpoint |
| Code | Delete obviously dead files |
| Database | Add indexes to slow queries |
| Dependencies | Remove unused packages |
当所有维度都需要优化时:
- 速度 - 用户会立刻感知到优化效果
- 依赖项 - 安全漏洞需优先处理
- 数据库 - 影响长期性能
- 代码 - 影响可维护性,对用户无直接影响
各维度快速优化方案:
| 维度 | 快速优化方案 |
|---|---|
| 速度 | 为最慢的API端点添加缓存 |
| 代码 | 删除明显废弃的文件 |
| 数据库 | 为慢查询添加索引 |
| 依赖项 | 移除未使用的包 |
Common Mistakes
常见错误
| Mistake | Fix |
|---|---|
| Optimizing before measuring | AUDIT first, always |
| Deleting code without checking | Verify no references before removing |
| Dropping database columns in production | Test migrations on staging |
| Updating all packages at once | Update one at a time, test each |
| Premature optimization | Wait until there's actual waste to clean |
| 错误 | 解决方法 |
|---|---|
| 未测量就优化 | 始终先执行审计步骤 |
| 未检查就删除代码 | 移除前确认无引用 |
| 直接在生产环境删除数据库字段 | 在 staging 环境测试迁移脚本 |
| 一次性更新所有包 | 逐个更新并测试 |
| 过早优化 | 等出现实际冗余后再清理 |
Success Looks Like
成功标准
✅ Pages load < 3 seconds
✅ No unused code in codebase
✅ No orphaned data in database
✅ No unused dependencies
✅ Bundle size < 200KB (React apps)
✅ Zero security vulnerabilities
✅ Automated checks prevent future waste
✅ 页面加载时间 < 3秒
✅ 代码库无未使用代码
✅ 数据库无孤立数据
✅ 无未使用依赖项
✅ 打包体积 < 200KB (React 应用)
✅ 零安全漏洞
✅ 自动化检查可避免未来冗余