Skip to content

perf: facade search bypasses FTS5 + startup overhead + sync_bridge thread-per-call #472

Closed

Description

@Sinity

Problems

Facade search() bypasses FTS5

operations/archive.py:382-410 — Polylogue().search("query") does NOT use FTS5. It scans messages.text with Python str.find() — O(n) per conversation, no FTS5 snippet(), no ranking. The correct FTS5 path (search_runtime.py:search_messages()) is only reachable through the sync search.py module, not the async facade.

--help loads all CLI modules at import time

cli/click_app.py:13-28 imports all 14+ CLI sub-modules at module level, which cascade-import Rich, config, query system. Database is NOT opened for --help, but import overhead adds measurable startup latency.

run_coroutine_sync spawns thread per call

sync_bridge.py:15-38 — every call creates a new threading.Thread() + event loop via asyncio.run(). Called from 17+ locations across CLI, pipeline, products, showcase, site, lib. No centralized lifecycle management.

Affected code

  • operations/archive.py:382-410 — facade search
  • cli/click_app.py:13-28 — eager imports
  • sync_bridge.py:15-38 — thread-per-call
  • 17+ call sites of run_coroutine_sync()

Fix direction

  • Route facade search() through FTS5 search provider when available
  • Lazy-import CLI modules (pattern already used in storage/__init__.py)
  • Consolidate sync bridge into the SyncPolylogue facade instead of 17 scattered call sites

Discovered during adversarial audit 2026-04-26.


Severity note (2026-04-26): While technically a correctness gap, NFD content in JSON export files is extremely rare in practice. Python’s json.loads preserves the original byte representation, and virtually all AI export files use NFC encoding. This should be treated as LOW severity — fix when touching the hashing pipeline, but not urgent.

Activity

  1. added
    type:perf
    area:core
    on Apr 26, 2026
  2. added a commit that references this issue on Apr 26, 2026
    34cb2c5
  3. Sinity commented on Apr 26, 2026

    @Sinity
    OwnerAuthor

    Resolved by #489

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:coretype:perf

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions