Skip to content

search_recording redoes whole-index work on every query, and the per-segment grouping is quadratic #346

Closed

Description

@TMHSDigital

Summary

Every searchIndex call flattens every item in the index (OCR lines, events, transcript, and up to 50,000 log lines), re-masks all of them through the vm regex scan, and re-normalizes them. For a multi-word query, it then builds per-segment lists with bySeg.set(item.seg, [...(bySeg.get(item.seg) ?? []), i]), which copies the list on every item (O(k^2) per segment). With no input, library search reads and parses every *.index.json under SCREENCAST_HOME on each call. Nothing is cached, and all of it runs synchronously in the stdio server.

Where

  • src/utils/recordingIndex.ts:418-420 (re-mask per query), :436 (normalize), :441-442 (bySeg spread), :527-528 (searchLibrary)
  • src/tools/searchRecording.ts:56-60

Impact

A segment with 20k items (a burst of log lines) costs about 2e8 element copies (roughly 1 s) per multi-word query. A library of about 100 indexed recordings is re-read, re-parsed and re-masked in full on every library query. While this runs, the server answers no other request.

Suggested fix

Acceptance criteria

  • A multi-word query over a 50k-item index runs in linear time (benchmark or test with a synthetic index).
  • Library search does not re-parse unchanged index files.

Getting started

  • Relevant files: src/utils/recordingIndex.ts, src/tools/searchRecording.ts
  • How to run tests: npm test

Filed by repo-audit/full-audit at b9b94fa. Severity: medium. Effort: M. audit-key: performance|src/utils/recordingIndex.ts|searchIndex

Activity

  1. added
    performance
    effort: medium
    on Nov 17, 2026
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

    effort: mediumperformancepriority: medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions