optimize

A command for reviewing application performance across a Rust backend, React frontend, and SQLite database. It uses profiling, benchmarking, query-plan checks, and a list of common bottlenecks.

In plain words
What is it for?
Use it to investigate slow calculations, large-list rendering, database queries, cloning, caching, parallel processing, and N+1 queries. It also organizes findings by priority.
Why use it?
It helps locate slow code, unnecessary work, rendering delays, and inefficient database queries before suggesting what to improve.

Command for Claude Code

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add commands/cacr92/wereply/optimize
Clone the repo
git clone --depth 1 https://github.com/cacr92/WeReply

Made for: Claude Code.

Per session 0 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 861 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.00861
Opus 5 $0.00000 $0.00430
Sonnet 5 $0.00000 $0.00172
Haiku 4.5 $0.00000 $0.00086

Measured 2d ago against content hash 2b4e3c484b54, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

optimize scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.claude/commands/optimize.md · 122 lines

What it actually says

/optimize - 性能优化分析

用途

识别性能瓶颈并提供具体的优化建议。

分析步骤

1. Rust 后端性能分析

识别热点代码
# 使用 cargo-flamegraph 生成火焰图
cargo flamegraph --bin cacrfeedformula

# 使用 criterion 进行基准测试
cargo bench
检查点
  • 是否有不必要的克隆?
  • 是否可以使用并行计算(Rayon)?
  • 是否可以添加缓存(Moka)?
  • 数据库查询是否优化?
  • 是否有 N+1 查询问题?

2. React 前端性能分析

使用 React DevTools Profiler
// 识别重渲染问题
// 检查是否需要:
// - React.memo
// - useCallback
// - useMemo
检查点
  • 组件是否过度渲染?
  • 是否需要虚拟滚动(大列表)?
  • 是否需要代码分割(lazy loading)?
  • 是否有内存泄漏?

3. 数据库性能分析

SQLite 优化
-- 检查查询计划
EXPLAIN QUERY PLAN SELECT ...;

-- 检查索引使用
PRAGMA index_list('table_name');

-- 检查表统计信息
ANALYZE;
检查点
  • 是否有缺失的索引?
  • 是否有未使用的索引?
  • 查询是否可以优化?
  • 是否需要批量操作?

优化建议模板

## 性能优化建议

### 高优先级(立即修复)
1. **配方优化计算耗时过长**
   - 问题:单次优化耗时 15 秒
   - 原因:未使用缓存,重复计算
   - 建议:添加 Moka 缓存,缓存原料数据
   - 预期改进:耗时减少到 3 秒

2. **原料列表渲染卡顿**
   - 问题:1000+ 原料渲染缓慢
   - 原因:��使用虚拟滚动
   - 建议:使用 react-window
   - 预期改进:渲染时间从 2 秒降到 200ms

### 中优先级(计划修复)
1. **数据库查询慢**
   - 问题:配方列表查询耗时 500ms
   - 原因:缺少索引
   - 建议:添加 species_code 索引
   - 预期改进:查询时间降到 50ms

### 低优先级(可选优化)
1. **启动时间优化**
   - 问题:应用启动耗时 3 秒
   - 原因:启动时加载所有数据
   - 建议:延迟加载非关键数据
   - 预期改进:启动时间降到 1.5 秒

性能基准

目标指标

  • 应用启动时间: < 2 秒
  • 配方优化计算: < 5 秒
  • 数据库查询: < 100ms
  • UI 响应时间: < 100ms
  • 大列表渲染: < 500ms

测量工具

  • Rust: cargo-flamegraph, criterion
  • React: React DevTools Profiler
  • 数据库: EXPLAIN QUERY PLAN
  • 整体: Chrome DevTools Performance

何时使用

  • 发现性能问题时
  • 定期性能审查
  • 重大功能上线前
  • 用户反馈卡顿时

相关 Skills

  • rust-optimization
  • react-typescript-development
  • sqlite-optimization
  • performance-standards (规范文件)
Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 122 lines · 0 tokens per session scan A 2b4e3c484b54

Subscribe to this mod's changes

optimize is a command published in the GitHub repository cacr92/WeReply (6 stars, last pushed 7mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 861 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.