Repository navigation
Description
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.tsopens it withnew Database(path)and onlyauto_vacuum,journal_modeandbusy_timeoutpragmas), so the SQLite page cache is the default 2 MB.
Steps to reproduce
- Track several repositories in the GitHub plugin (project repositories or the
extraRepossetting) 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. - In a thread composer, type
@and then one or more characters. - Each debounced keystroke calls
searchon both providers. Each call runslistCachedItems({ 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
LIMITandSELECT *: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:
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: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):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/githubloads the real plugin withcreateFakePluginHost(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'searchcalls. - With
LIMIT 8alone, the 40-repository case is still 11-16 ms, because SQLite must still read every row to find the newest 8. WithLIMIT 8and an index onitems (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, titlewithout 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 issuesandbb github prsCLI commands and thelistItemsRPC return the full list on purpose and are not part of this issue.
AGENT GENERATED
Activity
bb-slop-cop commentedon Nov 26, 2026
🚨 SLOP COP 🚨 ·
new-issue-autopilotplugins,github,perf,confirmed-repro.confirmed-repro.Answer GitHub mention searches from an index with a limit of 8 (get-b…
Answer GitHub mention searches from an index with a limit of 8 (get-b…