performance-optimisation

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Performance Optimisation Skill

性能优化技能

Tooling Notes

工具使用说明

This skill should only use read-only commands and avoid modifying files.
本技能仅应使用只读命令,避免修改文件。

Workflow

工作流程

Copy this checklist and use it to track your progress through the performance optimisation process:
markdown
Performance Optimisation Checklist

- [ ] Measure Baseline Performance
  - [ ] Use profiling tools to gather performance metrics.
  - [ ] Identify slow functions, database queries, and network requests.
- [ ] Identify Bottlenecks
  - [ ] Analyse profiling data to pinpoint performance issues.
  - [ ] Prioritise issues based on impact and ease of resolution.
- [ ] Implement Optimisations
  - [ ] Optimise algorithms and data structures.
  - [ ] Improve database query efficiency.
  - [ ] Reduce network latency and payload sizes.
  - [ ] Implement caching strategies where appropriate.
- [ ] Validate Improvements
  - [ ] Re-measure performance after optimisations.
  - [ ] Ensure that optimisations have led to measurable improvements.
- [ ] Document Changes
  - [ ] Update documentation to reflect performance changes.
  - [ ] Provide explanations for significant optimisations.
复制以下清单,用于跟踪性能优化过程的进度:
markdown
性能优化清单

- [ ] 测量基准性能
  - [ ] 使用性能分析工具收集性能指标。
  - [ ] 识别缓慢的函数、数据库查询和网络请求。
- [ ] 识别性能瓶颈
  - [ ] 分析性能分析数据以定位性能问题。
  - [ ] 根据影响程度和解决难度对问题进行优先级排序。
- [ ] 实施优化方案
  - [ ] 优化算法和数据结构。
  - [ ] 提升数据库查询效率。
  - [ ] 减少网络延迟和负载大小。
  - [ ] 在合适的场景下实施缓存策略。
- [ ] 验证优化效果
  - [ ] 优化后重新测量性能。
  - [ ] 确保优化措施带来了可量化的性能提升。
- [ ] 记录变更
  - [ ] 更新文档以反映性能相关变更。
  - [ ] 对重大优化措施提供说明。

Profiling Commands

性能分析命令

bash
undefined
bash
undefined

Node.js profiling

Node.js 性能分析

node --prof app.js node --prof-process isolate-0x*.log > processed.txt
node --prof app.js node --prof-process isolate-0x*.log > processed.txt

Python profiling

Python 性能分析

python -m cProfile -o profile.out app.py snakeviz profile.out
python -m cProfile -o profile.out app.py snakeviz profile.out

Database query analysis (PostgreSQL example)

数据库查询分析(PostgreSQL示例)

EXPLAIN ANALYZE SELECT * FROM your_table WHERE condition;
EXPLAIN ANALYZE SELECT * FROM your_table WHERE condition;

Web performance analysis

Web性能分析

lighthouse https://yourwebsite.com --output html --output-path report.html
undefined
lighthouse https://yourwebsite.com --output html --output-path report.html
undefined

Common Bottlenecks and Ways to Fix Them

常见性能瓶颈及解决方法

  • Inefficient Algorithms: Replace with more efficient algorithms or data structures.
  • Database Query Performance: Optimize queries, add indexes, or denormalize data.
  • Network Latency: Minimize requests, use CDNs, and compress payloads.
  • Unnecessary Computations: Cache results of expensive operations.
  • Memory Leaks: Identify and fix memory leaks to improve performance over time.
  • 低效算法:替换为更高效的算法或数据结构。
  • 数据库查询性能:优化查询语句、添加索引或进行数据反规范化。
  • 网络延迟:减少请求数量、使用CDN并压缩负载。
  • 不必要的计算:缓存高开销操作的结果。
  • 内存泄漏:识别并修复内存泄漏以提升长期性能。