← 返回
未分类

OpenClaw Performance

Performance analysis and optimization. Profiles code execution, identifies bottlenecks, and suggests optimizations.
性能分析与优化:剖析代码执行,定位瓶颈并提出优化建议。
michealxie001 michealxie001 来源
未分类 clawhub v1.1.0 1 版本 100000 Key: 无需
★ 0
Stars
📥 365
下载
💾 0
安装
1
版本
#latest

概述

Performance - Performance Analysis

性能分析工具,分析代码执行、识别瓶颈、提供优化建议。

Version: 1.1

Features: 性能分析、瓶颈识别、优化建议、基准测试、C/C++ 支持 (NEW)


Quick Start

1. 分析 Python 代码

# 分析函数执行时间
python3 scripts/main.py profile --file src/main.py --function process_data

# 分析整个模块
python3 scripts/main.py profile --file src/main.py

2. 识别瓶颈

# 扫描代码中的性能问题
python3 scripts/main.py analyze --file src/main.py

# 分析目录
python3 scripts/main.py analyze --dir src/

3. 基准测试

# 运行基准测试
python3 scripts/main.py benchmark --file src/main.py --function heavy_computation

Commands

命令说明示例
------------------
profile性能分析profile --file src.py
analyze瓶颈分析analyze --file src.py
benchmark基准测试benchmark --function foo

Profile 输出

$ python3 scripts/main.py profile --file src/processor.py --function process_data

🔍 Performance Profile
======================

Function: process_data
File: src/processor.py:45
Calls: 100
Total time: 2.34s
Avg time: 23.4ms

Top hotspots:
  45% - database.query() (line 67)
  30% - json.dumps() (line 89)
  15% - data transformation (line 78)
  10% - other

Recommendations:
  ⚠️  Consider caching database results
  ⚠️  Use orjson instead of json for better performance

瓶颈分析

$ python3 scripts/main.py analyze --file src/api.py

🔍 Performance Analysis
=======================

File: src/api.py
Issues found: 3

🔴 High Impact:
  Line 34: Nested loop O(n²)
    for user in users:
      for order in orders:  # ← N+1 query pattern
  
  Suggestion: Use JOIN query instead

🟡 Medium Impact:
  Line 67: String concatenation in loop
    result += item  # ← Use list + join instead

🟢 Low Impact:
  Line 89: Unused import
    import heavy_module  # ← Remove if not used

基准测试

$ python3 scripts/main.py benchmark --file src/sort.py --function quicksort

⏱️  Benchmark Results
====================

Function: quicksort
Iterations: 1000

Time (ms):
  Mean:   12.34
  Median: 11.89
  Min:     8.45
  Max:    45.67
  P95:    18.90
  P99:    32.10

Memory (MB):
  Mean:   2.45
  Peak:   4.12

Comparison:
  vs bubble sort: 45x faster
  vs merge sort:  1.2x faster

检测的优化模式

代码层面

问题检测建议
------------------
N+1 查询使用 JOIN / select_related
循环内字符串拼接使用 list + join
未使用的导入移除导入
嵌套循环优化算法或使用哈希
重复计算缓存结果

Python 特定

问题检测建议
------------------
list vs generator大数据用 generator
dict.get() vs []使用 .get() 避免 KeyError
列表推导式替代 map/filter

Configuration

.performance.json:

{
  "benchmark_iterations": 1000,
  "warmup_iterations": 10,
  "profile_lines": true,
  "check_patterns": [
    "n_plus_one",
    "string_concat_in_loop",
    "unused_imports"
  ]
}

CI/CD 集成

# .github/workflows/performance.yml
name: Performance Check
on: [pull_request]

jobs:
  perf:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      
      - name: Analyze Performance
        run: python3 skills/performance/scripts/main.py analyze --dir src/
      
      - name: Run Benchmarks
        run: python3 skills/performance/scripts/main.py benchmark --all

Files

skills/performance/
├── SKILL.md                    # 本文件
└── scripts/
    ├── main.py                 # ⭐ 统一入口
    ├── profiler.py             # 性能分析器
    └── analyzer.py             # 瓶颈分析器

Roadmap

  • [x] Basic profiling
  • [x] Bottleneck detection
  • [x] Benchmark runner
  • [ ] Memory profiling
  • [ ] Flame graph generation

版本历史

共 1 个版本

  • v1.1.0 当前
    2026-05-07 05:40 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

content-creation

中文学术论文写作助手

michealxie001
中文论文写作全流程助手,覆盖选题、构思、大纲、开题报告、文献综述、分章写作、引用管理、语言润色、投稿自检。专为中文、历史、哲学、文学等人文学科设计,内置《中华文哲研究集刊》等引用规范,支持脚注与参考文献自动格式化。仅基于用户提供真实资料,绝
★ 5 📥 1,697
dev-programming

Github

steipete
使用 `gh` CLI 与 GitHub 交互,通过 `gh issue`、`gh pr`、`gh run` 和 `gh api` 管理议题、PR、CI 运行及高级查询。
★ 681 📥 329,421
dev-programming

CodeConductor.ai

larsonreever
AI驱动平台,提供快速全栈开发、智能体、工作流自动化及低代码AI集成的可扩展产品创建。
★ 76 📥 182,452