google-research/perch-hoplite

Investigate better threading in SQLIteUsearchImpl

Open

#127 opened on May 12, 2026

View on GitHub
 (0 comments) (0 reactions) (0 assignees)Python (31 forks)github user discovery
good first issue

Repository metrics

Stars
 (115 stars)
PR merge metrics
 (PR metrics pending)

Description

Currently, we make a thread_split copy of the DB for each thread. Phil points out that we might be able to use the thread-local cursor instead, and save a whole pile of overhead.

From Phil's modified SQLiteUsearchImpl:

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        # Create a thread-local storage container
        self._thread_local = threading.local()


    def _get_cursor(self) -> sqlite3.Cursor:
        """
        Override: Returns a thread-local cursor. 
        If the current thread doesn't have one, it creates it.
        """
        if not hasattr(self._thread_local, 'cursor'):
            self._thread_local.cursor = self.db.cursor()
        return self._thread_local.cursor

Contributor guide