Files
mev-beta/.gemini/commands/reduce-memory.md
2025-09-14 10:09:55 -05:00

1.5 KiB

Reduce Memory Allocations

Reduce memory allocations in the following hot path: $ARGUMENTS

Memory Optimization Strategy:

1. Allocation Analysis

  • Identify high-frequency allocation points
  • Measure current allocation rates and patterns
  • Analyze garbage collection pressure

2. Optimization Techniques

Object Pooling

  • Implement sync.Pool for frequently created objects
  • Pool buffers, structs, and temporary objects
  • Proper reset patterns for pooled objects

Pre-allocation

  • Pre-allocate slices and maps when size is predictable
  • Reuse existing data structures
  • Avoid repeated allocations in loops

Buffer Reuse

  • Reuse byte buffers and string builders
  • Implement buffer pools for I/O operations
  • Minimize string concatenation

3. MEV Bot Specific Optimizations

Transaction Processing

  • Pool transaction objects and event structures
  • Reuse parsing buffers
  • Optimize log and metric object creation

Mathematical Calculations

  • Pool uint256 and big.Int objects
  • Reuse temporary calculation buffers
  • Optimize precision object handling

Implementation Guidelines:

  • Measure allocation reduction with benchmarks
  • Monitor garbage collection statistics
  • Ensure thread safety in pooled objects
  • Maintain code readability and maintainability

Deliverables:

  • Memory allocation reduction benchmarks
  • Optimized code with pooling strategies
  • GC pressure analysis before and after
  • Memory usage monitoring enhancements
  • Best practices documentation for team