# Qwen Code Performance Optimization Settings ## Workflow Preferences - **Always commit changes**: Use `git commit -am "math: descriptive message"` for mathematical implementations - **Branch naming**: Use prefixes (`math-sqrt-price`, `algo-liquidity-calc`, `perf-uniswap`) - **Context management**: Focus on mathematical precision and performance - **Parallel processing**: Leverage Go's concurrency patterns for independent calculations ## File Organization Preferences - **Mathematical functions**: Place in `pkg/uniswap/` or `pkg/math/` - **Test files**: Place alongside source files with `_test.go` suffix - **Documentation**: Inline comments explaining mathematical formulas - **Precision libraries**: Use `github.com/holiman/uint256` for uint256 arithmetic ## Performance Monitoring ```bash # Enable metrics endpoint for performance tracking export METRICS_ENABLED="true" export METRICS_PORT="9090" # Monitor memory usage of mathematical calculations go tool pprof http://localhost:9090/debug/pprof/heap # Monitor CPU usage of mathematical functions go tool pprof http://localhost:9090/debug/pprof/profile?seconds=30 # Run benchmarks for mathematical functions go test -bench=. -benchmem ./pkg/uniswap/... # Compare before/after performance of cached functions go test -bench=BenchmarkSqrtPriceX96ToPrice ./pkg/uniswap/... # Original go test -bench=BenchmarkSqrtPriceX96ToPriceCached ./pkg/uniswap/... # Cached version ``` ## Precision Requirements - **Uint256 Arithmetic**: Use `github.com/holiman/uint256` for all uint256 calculations - **Floating Point**: Use `math/big` for floating-point calculations when needed - **Rounding**: Implement proper rounding strategies for financial calculations - **Overflow Handling**: Handle overflow and underflow conditions properly ## Optimization Focus Areas 1. **Mathematical Computation Efficiency** - Minimize computational overhead in pricing functions - Optimize sqrtPriceX96 to price conversions (Successfully achieved: SqrtPriceX96ToPriceCached 24% faster than original) - Efficient tick calculations 2. **Memory Allocation Reduction** - Object pooling for frequently created mathematical objects - Pre-allocation of slices and buffers - Minimize garbage collection pressure (Successfully achieved: 20-33% reduction in allocations) 3. **Algorithmic Optimization** - Mathematical formula simplification - Lookup table implementation for repeated calculations - Caching strategies for expensive computations (Successfully implemented: Precomputing expensive constants `2^96`, `2^192`)