8.7 KiB
8.7 KiB
Gemini CLI Configuration
This directory contains Gemini configuration and tools for the MEV Bot project.
🚀 Quick Start Commands
Essential Build & Test Commands
# Build the MEV bot binary
make build
# Run performance tests
.gemini/scripts/perf-test.sh
# Run optimization analysis
.gemini/scripts/optimize.sh
# Run benchmarks with profiling
make bench-profile
# Run concurrency tests
make test-concurrent
# Check for Go modules issues
go mod tidy && go mod verify
# Run linter with performance focus
golangci-lint run --fast
Development Workflow Commands
# Setup development environment
export ARBITRUM_RPC_ENDPOINT="wss://arbitrum-mainnet.core.chainstack.com/73bc682fe9c5bd23b42ef40f752fa89a"
export ARBITRUM_WS_ENDPOINT="wss://arbitrum-mainnet.core.chainstack.com/73bc682fe9c5bd23b42ef40f752fa89a"
export METRICS_ENABLED="true"
# Run with timeout for testing
timeout 60 ./mev-bot start
# Debug with verbose logging
LOG_LEVEL=debug ./mev-bot start
# Profile performance with detailed analysis
.gemini/scripts/profile.sh
Gemini Commands Directory
The .gemini/commands/ directory contains predefined commands for performance optimization tasks:
optimize-performance.md- Optimize application performanceanalyze-bottlenecks.md- Analyze performance bottleneckstune-concurrency.md- Tune concurrency patternsreduce-memory.md- Reduce memory allocationsimprove-latency.md- Improve latency performance
Gemini Settings
The .gemini/settings.json file contains Gemini's performance optimization configuration:
{
"focus_areas": [
"Algorithmic Implementations",
"Performance Optimization",
"Concurrency Patterns",
"Memory Management"
],
"primary_skills": [
"Optimizing mathematical calculations for performance",
"Profiling and identifying bottlenecks in critical paths",
"Reducing memory allocations in hot code paths",
"Optimizing concurrency patterns for maximum throughput"
],
"performance_optimization": {
"enabled": true,
"profiling": {
"cpu": true,
"memory": true,
"goroutine": true,
"mutex": true
},
"optimization_targets": [
"Reduce latency to < 10 microseconds for critical path",
"Achieve > 100,000 messages/second throughput",
"Minimize memory allocations in hot paths",
"Optimize garbage collection tuning"
]
},
"concurrency": {
"worker_pools": true,
"pipeline_patterns": true,
"fan_in_out": true,
"backpressure_handling": true
},
"benchmarking": {
"baseline_comparison": true,
"regression_detection": true,
"continuous_monitoring": true
}
}
📋 Development Guidelines & Code Style
Performance Optimization Guidelines
- Profiling First: Always profile before optimizing
- Measure Impact: Measure performance impact of changes
- Maintain Readability: Don't sacrifice code readability for marginal gains
- Focus on Hot Paths: Optimize critical code paths first
- Test Regressions: Ensure optimizations don't cause regressions
Concurrency Patterns
- Worker Pools: Use worker pools for parallel processing
- Pipeline Patterns: Implement pipeline patterns for multi-stage processing
- Fan-in/Fan-out: Use fan-in/fan-out patterns for data distribution
- Backpressure Handling: Implement proper backpressure handling
Memory Management
- Object Pooling: Use sync.Pool for frequently created objects
- Pre-allocation: Pre-allocate slices and maps when size is known
- Minimize Allocations: Reduce allocations in hot paths
- GC Tuning: Properly tune garbage collection
Required Checks Before Commit
# Run performance tests
.gemini/scripts/perf-test.sh
# Run benchmark comparisons
.gemini/scripts/bench-compare.sh
# Check for performance regressions
.gemini/scripts/regression-check.sh
Gemini's Primary Focus Areas
As Gemini, you're particularly skilled at:
-
Algorithmic Implementations and Mathematical Computations
- Implementing precise Uniswap V3 pricing functions
- Optimizing mathematical calculations for performance
- Ensuring numerical stability and precision
- Creating efficient algorithms for arbitrage detection
-
Optimizing Performance and Efficiency
- Profiling and identifying bottlenecks in critical paths
- Reducing memory allocations in hot code paths
- Optimizing concurrency patterns for maximum throughput
- Tuning garbage collection for low-latency requirements
-
Understanding Complex Uniswap V3 Pricing Functions
- Implementing accurate tick and sqrtPriceX96 conversions
- Calculating price impact with proper precision handling
- Working with liquidity and fee calculations
- Handling edge cases in pricing mathematics
-
Implementing Concurrent and Parallel Processing Patterns
- Designing efficient worker pool implementations
- Creating robust pipeline processing systems
- Managing synchronization primitives correctly
- Preventing race conditions and deadlocks
-
Working with Low-Level System Operations
- Optimizing memory usage and allocation patterns
- Tuning system-level parameters for performance
- Implementing efficient data structures for high-frequency access
- Working with CPU cache optimization techniques
🛠 Gemini Optimization Settings
Workflow Preferences
- Always profile first: Use
go tool pprofbefore making changes - Branch naming: Use prefixes (
perf-worker-pool,opt-pipeline,tune-gc) - Context management: Focus on performance metrics and bottlenecks
- Continuous monitoring: Implement monitoring for performance metrics
File Organization Preferences
- Performance-critical code: Place in
pkg/market/orpkg/monitor/ - Benchmark files: Place alongside source files with
_bench_test.gosuffix - Profiling scripts: Place in
.gemini/scripts/ - Optimization documentation: Inline comments explaining optimization approaches
Performance Monitoring
# Enable detailed metrics endpoint
export METRICS_ENABLED="true"
export METRICS_PORT="9090"
# Monitor all performance aspects
go tool pprof http://localhost:9090/debug/pprof/profile?seconds=30
go tool pprof http://localhost:9090/debug/pprof/heap
go tool pprof http://localhost:9090/debug/pprof/goroutine
go tool pprof http://localhost:9090/debug/pprof/mutex
# Run comprehensive performance analysis
.gemini/scripts/profile.sh
🔧 Environment Configuration
Required Environment Variables
# Arbitrum RPC Configuration
export ARBITRUM_RPC_ENDPOINT="wss://arbitrum-mainnet.core.chainstack.com/73bc682fe9c5bd23b42ef40f752fa89a"
export ARBITRUM_WS_ENDPOINT="wss://arbitrum-mainnet.core.chainstack.com/73bc682fe9c5bd23b42ef40f752fa89a"
# Application Configuration
export LOG_LEVEL="info"
export METRICS_ENABLED="true"
export METRICS_PORT="9090"
# Development Configuration
export GO_ENV="development"
export DEBUG="true"
# Performance Configuration
export GOGC=20
export GOMAXPROCS=0
export CONCURRENCY_LEVEL=100
Profiling Environment Variables
# Profiling Configuration
export PROFILING_ENABLED=true
export PROFILING_DURATION=30s
export PROFILING_OUTPUT_DIR=".gemini/profiles"
# Benchmark Configuration
export BENCHMARK_TIMEOUT=60s
export BENCHMARK_ITERATIONS=1000000
export BENCHMARK_CONCURRENCY=10
📝 Commit Message Conventions
Format
perf(type): brief description
- Detailed explanation of performance optimization
- Measured impact of the change
- Profiling data supporting the optimization
🤖 Generated with [Gemini](https://gemini.example.com)
Co-Authored-By: Gemini <noreply@gemini.example.com>
Types
worker-pool: Worker pool optimizationspipeline: Pipeline pattern optimizationsmemory: Memory allocation reductionsgc: Garbage collection tuningconcurrency: Concurrency pattern improvementsalgorithm: Algorithmic optimizationslatency: Latency improvementsthroughput: Throughput improvements
🚨 Performance Guidelines
Always Profile
- Use
go tool pprofto identify bottlenecks - Measure baseline performance before optimization
- Compare performance before and after changes
- Monitor for regressions in unrelated areas
Focus Areas
- Critical Path: Optimize the most time-consuming operations
- Hot Paths: Reduce allocations in frequently called functions
- Concurrency: Improve parallel processing efficiency
- Memory: Minimize memory usage and GC pressure
Testing Performance
# Run comprehensive performance tests
.gemini/scripts/perf-test.sh
# Compare benchmarks
.gemini/scripts/bench-compare.sh
# Check for regressions
.gemini/scripts/regression-check.sh
# Generate flame graphs
.gemini/scripts/flame-graph.sh