Skip to content

GitHub issue and PR mention search reads the whole cache on every keystroke #8218

Description

@lanjak

Summary

When a person types @ or # in the composer, the GitHub plugin's issue and pr mention providers each run one SQLite query. The query has no LIMIT and no index. SQLite reads every cached row (open and closed, with bodies) and sorts all matches. The plugin then keeps 8. The cost grows with the number of tracked repositories: about 34 ms per keystroke at 40 repositories, synchronously in the server process.

Versions and environment

  • bb from source at origin/main 2a21dd56f69cb1b72d78f97d51e8d4d72f09fe2e.
  • Linux (CachyOS, kernel 7.3.4), Node v26.13.1.
  • No provider involved. The plugin database is opened with the host defaults (apps/server/src/services/plugins/plugin-api.ts opens it with new Database(path) and only auto_vacuum, journal_mode and busy_timeout pragmas), so the SQLite page cache is the default 2 MB.

Steps to reproduce

  1. Track several repositories in the GitHub plugin (project repositories or the extraRepos setting) and let it sync. Each sync keeps up to 100 open and 50 closed issues and 50 open and 30 closed pull requests per repository (ISSUE_PAGE, CLOSED_ISSUE_PAGE, PR_PAGE, CLOSED_PR_PAGE), so up to 230 rows per repository.
  2. In a thread composer, type @ and then one or more characters.
  3. Each debounced keystroke calls search on both providers. Each call runs listCachedItems({ kind, query, state: "open" }) and then .slice(0, 8).

To see the plan, run this on the plugin database:

EXPLAIN QUERY PLAN SELECT * FROM items WHERE kind = 'issue' AND state = 'OPEN' AND (title LIKE '%a%' OR CAST(number AS TEXT) LIKE '%a%' OR repo LIKE '%a%') ORDER BY updated_at DESC;

Expected vs actual

Actual plan:

SCAN items | USE TEMP B-TREE FOR ORDER BY

Expected: a search that returns 8 results reads only the rows it needs, newest first, and stops after 8 matches.

Measured cost of one keystroke (issue and pr provider search together, median of 200 runs after 20 warm-up runs):

Tracked repos (rows) query "" query "a" query "fix" query "zzz" (no match)
1 (230) 0.38 ms 0.33 ms 0.13 ms 0.09 ms
10 (2,300) 5.65 ms 3.74 ms 0.80 ms 0.43 ms
40 (9,200) 33.58 ms 32.34 ms 18.35 ms 16.02 ms

Evidence

  • Query with no LIMIT and SELECT *:

    bb/plugins/github/server.ts

    Lines 762 to 801 in 2a21dd5

    function listCachedItems(options: {
    kind?: "issue" | "pr";
    repo?: string;
    query?: string;
    state?: "open" | "closed";
    assignee?: string;
    }): CachedItem[] {
    const clauses: string[] = [];
    const params: unknown[] = [];
    if (options.kind !== undefined) {
    clauses.push("kind = ?");
    params.push(options.kind);
    }
    if (options.repo !== undefined) {
    clauses.push("repo = ?");
    params.push(options.repo);
    }
    if (options.state === "open") {
    clauses.push("state = 'OPEN'");
    } else if (options.state === "closed") {
    clauses.push("state != 'OPEN'");
    }
    if (options.assignee !== undefined) {
    clauses.push("assignees LIKE ?");
    params.push(`%${JSON.stringify(options.assignee)}%`);
    }
    const query = options.query?.trim() ?? "";
    if (query.length > 0) {
    clauses.push(
    "(title LIKE ? OR CAST(number AS TEXT) LIKE ? OR repo LIKE ?)",
    );
    const like = `%${query.replace(/^#/, "")}%`;
    params.push(like, like, like);
    }
    const where = clauses.length > 0 ? `WHERE ${clauses.join(" AND ")}` : "";
    const rows = db
    .prepare(`SELECT * FROM items ${where} ORDER BY updated_at DESC`)
    .all(...params) as Record<string, unknown>[];
    return rows.map(rowToItem);
    }
  • Mention search keeps 8 of the full result:

    bb/plugins/github/server.ts

    Lines 1579 to 1587 in 2a21dd5

    function mentionItems(kind: "issue" | "pr", query: string) {
    return listCachedItems({ kind, query, state: "open" })
    .slice(0, 8)
    .map((item) => ({
    id: `${item.repo}#${item.number}`,
    title: `#${item.number} ${item.title}`,
    subtitle: item.repo,
    }));
    }
  • Both providers register the @ and # triggers:

    bb/plugins/github/server.ts

    Lines 1656 to 1678 in 2a21dd5

    bb.ui.registerMentionProvider({
    id: "issue",
    label: "GitHub issues",
    triggers: ["@", "#"],
    search({ query }) {
    return mentionItems("issue", query);
    },
    resolve(itemId) {
    return mentionContext("issue", itemId);
    },
    });
    bb.ui.registerMentionProvider({
    id: "pr",
    label: "GitHub pull requests",
    triggers: ["@", "#"],
    search({ query }) {
    return mentionItems("pr", query);
    },
    resolve(itemId) {
    return mentionContext("pr", itemId);
    },
    });
  • Table schema, no index besides the primary key (repo, kind, number):

    bb/plugins/github/server.ts

    Lines 721 to 736 in 2a21dd5

    bb.storage.migrate(db, [
    `CREATE TABLE IF NOT EXISTS items (
    repo TEXT NOT NULL,
    number INTEGER NOT NULL,
    kind TEXT NOT NULL,
    title TEXT NOT NULL,
    state TEXT NOT NULL,
    author TEXT NOT NULL,
    labels TEXT NOT NULL,
    url TEXT NOT NULL,
    body TEXT NOT NULL,
    updated_at TEXT NOT NULL,
    PRIMARY KEY (repo, kind, number)
    )`,
    `ALTER TABLE items ADD COLUMN assignees TEXT NOT NULL DEFAULT '[]'`,
    ]);
  • How it was measured: a temporary Vitest file in plugins/github loads the real plugin with createFakePluginHost (which uses a file-backed SQLite database like the host). It inserts rows with 3.5 KB bodies (the average open issue body in get-bb/bb), 230 per repository with the real open and closed split. It then times both providers' search calls.
  • With LIMIT 8 alone, the 40-repository case is still 11-16 ms, because SQLite must still read every row to find the newest 8. With LIMIT 8 and an index on items (kind, state, updated_at), every case above is at or below 0.41 ms, except the no-match case at 40 repositories (about 7 ms).

What you ruled out

  • Not a duplicate of fix: bound pending plugin mention searches #8003 or Abort mention searches the person has typed past #8047: those bound and abort pending plugin mention searches. This search is synchronous, so it cannot be aborted, and the cost is in each call.
  • Not a duplicate of Speed up Docs mention search #4006: that PR fixed the Docs plugin mention search, not the GitHub plugin.
  • Selecting only repo, number, title without an index still reads every row page, because the 3.5 KB body is in the same page as the row: 8.8 ms at 6,000 open rows (a run without closed rows).
  • The bb github issues and bb github prs CLI commands and the listItems RPC return the full list on purpose and are not part of this issue.

AGENT GENERATED

Activity

  1. added theissue type on Nov 26, 2026
  2. added
    plugins
    github
    confirmed-repro
    on Nov 26, 2026
  3. bb-slop-cop commented on Nov 26, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    • Classification: Bug · Medium priority · Low effort; labels: plugins, github, perf, confirmed-repro.
    • Reproduction and root-cause report: REPRODUCED, high root-cause confidence.
    • Root cause: mention search scans and sorts the cache, materializes every matching open row, then truncates to eight suggestions in JavaScript.
    • Evidence: the authored provider-level test fails on unchanged trusted main in two clean checkouts; 40 synthetic repositories load 4,000 issue rows + 2,000 PR rows for 8 + 8 suggestions. Reproduction label: confirmed-repro.
    • No new PR: existing open PR Answer GitHub mention searches from an index with a limit of 8 #8219 already closes this issue; a duplicate would not be safe.
  4. added a commit that references this issue on Nov 30, 2026
    4f4da12
  5. added a commit that references this issue on Dec 1, 2026
    85b78ec
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

    confirmed-reprogithubperfplugins

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions