Skip to content

Optimize performance and memory usage #22

@MartinPTielemans

Description

@MartinPTielemans

Description

The application could benefit from performance optimizations, especially around clipboard monitoring and memory management.

Current performance concerns:

Clipboard Monitoring

// In command.rs - monitors every clipboard change
fn on_clipboard_change(&mut self) {
    // Processes every clipboard change regardless of content
    if let Ok(current_clipboard) = self.clipboard_ctx.get_text() {
        // String comparison and translation on every change
    }
}

Memory Management

  • String allocations on every clipboard change
  • No cleanup of old clipboard history
  • Global static state that persists throughout app lifetime
  • Potential memory leaks in long-running sessions

CPU Usage

  • Continuous polling vs event-driven approach
  • Unnecessary translations for non-command text
  • Regex matching on every clipboard change

Proposed optimizations:

Smart Filtering

// Pre-filter clipboard content before processing
fn is_potential_command(text: &str) -> bool {
    text.starts_with("npm ") || text.starts_with("pnpm ") || 
    text.starts_with("yarn ") || text.starts_with("bun ") ||
    text.starts_with("npx ") || text.starts_with("pnpx ")
}

Caching Strategy

  • LRU cache for translated commands
  • Debouncing for rapid clipboard changes
  • Lazy evaluation of translation mappings

Memory Optimizations

  • String interning for common commands
  • Bounded clipboard history with automatic cleanup
  • Memory pool for frequent allocations

Performance Monitoring

  • Metrics collection for clipboard operations
  • Performance profiling in debug builds
  • Memory usage reporting for optimization

Benefits:

  • Reduced CPU usage during active monitoring
  • Lower memory footprint for long-running sessions
  • Better battery life on MacBooks
  • Improved responsiveness of the UI
  • Scalability for heavy clipboard usage

This would make the app more suitable for always-on usage without impacting system performance.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions