Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
453 changes: 51 additions & 402 deletions README.md

Large diffs are not rendered by default.

155 changes: 155 additions & 0 deletions performance-optimization-guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
# ClawX 性能优化指南

> **创建时间**: 2026-03-30 13:35
> **状态**: 火力全开 × 10

---

## 📖 目录

- [性能优化策略](#性能优化策略)
- [内存优化](#内存优化)
- [速度优化](#速度优化)

---

## ⚡ 性能优化策略

### 1. 模型选择
- **快速响应**: 使用小模型(Haiku)
- **复杂任务**: 使用大模型(Sonnet/Opus)
- **平衡选择**: 根据任务复杂度动态选择

### 2. 并发优化
```python
import asyncio

async def run_concurrent_tasks(tasks):
# 并发执行多个任务
results = await asyncio.gather(*[
agent.run(task)
for task in tasks
])
return results
```

### 3. 缓存策略
- 缓存常用结果
- 减少重复计算
- 优化 Token 使用

---

## 💾 内存优化

### 1. 上下文管理
```python
# 限制上下文长度
agent = Agent(
max_context_tokens=4000
)
```

### 2. 分块处理
```python
def chunk_large_file(file_path, chunk_size=10000):
with open(file_path) as f:
while True:
chunk = f.read(chunk_size)
if not chunk:
break
yield chunk
```

### 3. 垃圾回收
```python
import gc

async def process_with_cleanup(task):
result = await process(task)
gc.collect() # 手动触发垃圾回收
return result
```

---

## 🚀 速度优化

### 1. 流式输出
```python
async def stream_response(task):
async for chunk in agent.stream(task):
yield chunk
```

### 2. 批量处理
```python
async def batch_process(items):
# 批量处理,减少 API 调用
results = []
batch = []

for item in items:
batch.append(item)

if len(batch) >= 10:
results.extend(await process_batch(batch))
batch = []

if batch:
results.extend(await process_batch(batch))

return results
```

### 3. 预加载
```python
# 预加载常用模型
def preload_models():
models = ["haiku", "sonnet"]
for model in models:
load_model(model)
```

---

## 📊 性能监控

### 监控指标
- **响应时间**: 任务执行耗时
- **内存使用**: RAM 占用情况
- **Token 消耗**: API 调用量
- **错误率**: 失败任务比例

### 监控代码
```python
import time

class PerformanceMonitor:
def __init__(self):
self.metrics = []

async def track(self, func):
start = time.time()
result = await func()
elapsed = time.time() - start

self.metrics.append({
"function": func.__name__,
"time": elapsed
})

return result
```

---

## 🔗 相关资源

- **性能文档**: https://docs.clawx.ai/performance
- **优化案例**: https://github.com/clawx/examples

---

**整理者**: srxly888-creator
**时间**: 2026-03-30 13:35
4 changes: 4 additions & 0 deletions src/i18n/locales/en/cron.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
"discordChannelId": "Discord Channel ID",
"discordChannelIdPlaceholder": "e.g., 1438452657525100686",
"discordChannelIdDesc": "Right-click the Discord channel → Copy Channel ID",
"agentBinding": "Agent Binding",
"agentBindingDesc": "Bind this task to a specific agent to use its skills and configuration",
"selectAgent": "Select Agent",
"noAgent": "No agent binding",
"enableImmediately": "Enable immediately",
"enableImmediatelyDesc": "Start running this task after creation",
"saveChanges": "Save Changes"
Expand Down
17 changes: 17 additions & 0 deletions src/i18n/locales/en/skills.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,22 @@
"noResults": "No skills found matching your search.",
"emptyPrompt": "Search for new skills to expand your capabilities.",
"searchError": "ClawHub search failed. Check your connection or installation."
},
"scope": {
"title": "Scope",
"global": "Global",
"agent": "Agent",
"globalDesc": "Global scope: affects all agents",
"agentDesc": "Agent scope: affects only selected agent",
"selectAgent": "Select Agent",
"runtimeWarning": "Agent-scoped enforcement depends on OpenClaw runtime support. Currently effective in UI only.",
"effective": "Effective",
"override": "Override"
},
"policy": {
"title": "Skill Policy",
"globalEnabled": "Global Enabled",
"agentOverrides": "Agent Overrides",
"noOverrides": "No overrides configured"
}
}
4 changes: 4 additions & 0 deletions src/i18n/locales/zh/cron.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
"discordChannelId": "Discord 频道 ID",
"discordChannelIdPlaceholder": "例如:1438452657525100686",
"discordChannelIdDesc": "右键点击 Discord 频道 → 复制频道 ID",
"agentBinding": "智能体绑定",
"agentBindingDesc": "将此任务绑定到特定智能体以使用其技能和配置",
"selectAgent": "选择智能体",
"noAgent": "不绑定智能体",
"enableImmediately": "立即启用",
"enableImmediatelyDesc": "创建后立即开始运行此任务",
"saveChanges": "保存更改"
Expand Down
17 changes: 17 additions & 0 deletions src/i18n/locales/zh/skills.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,22 @@
"noResults": "未找到匹配的技能。",
"emptyPrompt": "搜索新技能以扩展您的能力。",
"searchError": "ClawHub 搜索失败。请检查您的连接或安装。"
},
"scope": {
"title": "作用域",
"global": "全局",
"agent": "智能体",
"globalDesc": "全局作用域:影响所有智能体",
"agentDesc": "智能体作用域:仅影响选中的智能体",
"selectAgent": "选择智能体",
"runtimeWarning": "智能体作用域的强制执行依赖于 OpenClaw 运行时支持。当前仅在 UI 中生效。",
"effective": "生效",
"override": "覆盖"
},
"policy": {
"title": "技能策略",
"globalEnabled": "全局启用",
"agentOverrides": "智能体覆盖",
"noOverrides": "暂无覆盖设置"
}
}