Files
mev-beta/.claude/commands/optimize-performance.md
2025-09-14 10:09:55 -05:00

84 lines
2.1 KiB
Markdown

# Optimize Performance
Optimize the performance of the MEV bot in the following area: $ARGUMENTS
## Performance Optimization Strategy:
### 1. **Profiling and Measurement**
```bash
# CPU profiling
go tool pprof http://localhost:9090/debug/pprof/profile?seconds=30
# Memory profiling
go tool pprof http://localhost:9090/debug/pprof/heap
# Trace analysis
go tool trace trace.out
# Benchmark testing
go test -bench=. -benchmem ./...
```
### 2. **Optimization Areas**
#### **Concurrency Optimization**
- Worker pool sizing and configuration
- Channel buffer optimization
- Goroutine pooling and reuse
- Lock contention reduction
- Context cancellation patterns
#### **Memory Optimization**
- Object pooling for frequent allocations
- Buffer reuse patterns
- Garbage collection tuning
- Memory leak prevention
- Slice and map pre-allocation
#### **I/O Optimization**
- Connection pooling for RPC calls
- Request batching and pipelining
- Caching frequently accessed data
- Asynchronous processing patterns
- Rate limiting optimization
#### **Algorithm Optimization**
- Uniswap math calculation efficiency
- Event parsing performance
- Data structure selection
- Caching strategies
- Indexing improvements
### 3. **MEV Bot Specific Optimizations**
#### **Transaction Processing Pipeline**
- Parallel transaction processing
- Event filtering optimization
- Batch processing strategies
- Pipeline stage optimization
#### **Market Analysis**
- Price calculation caching
- Pool data caching
- Historical data indexing
- Real-time processing optimization
#### **Arbitrage Detection**
- Opportunity scanning efficiency
- Profit calculation optimization
- Market impact analysis speed
- Cross-DEX comparison performance
## Implementation Guidelines:
- Measure before optimizing (baseline metrics)
- Focus on bottlenecks identified through profiling
- Maintain code readability and maintainability
- Add performance tests for regressions
- Document performance characteristics
## Deliverables:
- Performance benchmark results (before/after)
- Optimized code with maintained functionality
- Performance monitoring enhancements
- Optimization documentation
- Regression test suite