Skip to content

perf: Implement Async Worker Pattern for Daemon Mode to Prevent Re-initialization #41

@BETAER-08

Description

@BETAER-08

Problem

Currently, the FileWatcher in daemon mode calls Indexer::update_file synchronously on every file change. This causes the heavy EmbeddingEngine and SQLite DB connections to be re-initialized from scratch every time. When a user saves multiple files rapidly or switches branches, this leads to severe performance bottlenecks, high memory spikes, and event processing delays.

Proposed Solution

  • Separate the file watching logic from the processing logic in src/daemon/watcher.rs.
  • Introduce a background Worker thread that initializes and holds a long-lived instance of EmbeddingEngine and ContextDb in memory.
  • Implement an mpsc (Multi-Producer, Single-Consumer) channel to pass file change events from the Watcher to the Worker.

Definition of Done

  • Watcher and Worker are separated into different threads.
  • mpsc channel successfully transmits events between Watcher and Worker.
  • EmbeddingEngine is loaded only once when the daemon starts and reused.
  • Rapid sequential file saves do not cause the daemon to freeze or crash.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: daemonLogic for FileWatcher and background processes.enhancementNew feature or request (e.g., config file, depth control).priority: highImportant features that should be addressed soon.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions