Repository navigation
Description
Summary
On a remote bb server, the / command menu often took 0.4–2.9s to open. Profiling shows two separate costs:
- Steady cost: the
/commandsrequest made several serial server→host-daemon round trips, and desktop did nothing ahead of time. That was about 0.3–0.6s on every lookup. - Variance: the server's main thread was regularly blocked by its own work, and every round trip queued behind it. This produced the 1–3s cases, and up to a minute during the hourly vacuum.
The single biggest bottleneck is the hourly incremental vacuum, which blocks the whole server for 9–69s every hour. Next are timeline rebuilds on long-running threads (0.2–9s each). Round trips and filesystem scanning are a much smaller share.
Every bb server runs this vacuum hourly once more than 1,024 pages are free. How long it blocks depends on database size and hardware. Each server is single-user, and a stall affects every device and daemon connected to that server.
Where the time goes
| # | Bottleneck | Measured cost | Scope | Tracking |
|---|---|---|---|---|
| 1 | Hourly incremental_vacuum(20000) runs in one synchronous call |
9–69s every hour; 1,087s over 30h | All requests on the server | #5193 (fix) |
| 2 | Timeline build reads the whole active turn | 0.2–9.5s per build; about 2,300 builds over 30h | Thread open and refresh, plus everything queued behind them | #4674 |
| 3 | listActiveBackgroundTaskCountsByThreadIds, CPU-bound |
p50 108ms, p99 186ms; 6,423 slow runs (721s) over 30h | Thread and sidebar responses (about 0.1s each) | not filed |
| 4 | Thread pruning advances | about 140ms each; 3,787 slow (530s) over 30h | Background, blocks the loop | partly fixed on main (#5124, #5115) |
| 5 | /commands: 2 serial daemon round trips for project skills, plus 1 for provider commands |
about 1 RTT (100–200ms) per serial trip; 13 RPCs per call with 10 skills | / lookup and thread start |
#5172 |
| 6 | Desktop composer doesn't prefetch the / catalog |
first / waits for the full request (0.4–1.8s) |
Desktop / |
#5171 |
| 7 | Daemon filesystem scan for commands and skills | 20–160ms | / lookup |
not worth changing |
| 8 | Server reads and hashes its own skills on each request | 15–25ms (48 skills) | / lookup |
not worth changing |
Rows 1–4 come from the server logs; rows 5–8 come from direct measurement.
Versions and environment
- Server:
0.45.1-nightly.37657450135.1(commit04c6371b8a), run by thebb-server.servicesystemd unit.- Linux, 4 vCPU, 7.9 GB RAM, 1.2 GB swap in use.
- Data dir
/root/bb-server/data.
- Client and host daemon: macOS 26.5.2, bb-app
0.45.1-nightly.37657450135.1, connected to the server over the network. Server↔daemon RTT is about 100–200ms. - Database:
bb.dbis 8.05 GB, with a 323 MB WAL.auto_vacuum=INCREMENTAL,page_size=4096.page_count=1,965,101andfreelist_count=1,026,702, so 4.2 GB (52%) of the file is free pages.
- The code cited below is unchanged between
04c6371b8aandmainat53c1e870d1, except where noted.
Steps to reproduce
A. / latency against a remote server
-
Connect a Mac host to a remote bb server, and open a project that has
.bb/skills. -
Time the endpoint the
/menu calls:for i in $(seq 8); do curl -s -o /dev/null -w "%{time_total} " "$BB_SERVER_URL/api/v1/projects/$PROJECT/commands?provider=claude-code&environmentId=$ENV"; done
-
Repeat with
provider=nonexistent. That returns before any daemon RPC, which gives you the baseline.
B. Vacuum stall, standalone (Node 22, node:sqlite):
import { DatabaseSync } from "node:sqlite";
const db = new DatabaseSync(process.argv[2]);
db.exec("PRAGMA page_size=4096; PRAGMA auto_vacuum=INCREMENTAL; PRAGMA journal_mode=WAL;");
db.exec("CREATE TABLE events(id INTEGER PRIMARY KEY, thread TEXT, data BLOB); CREATE INDEX ev_thread ON events(thread);");
const ins = db.prepare("INSERT INTO events(thread,data) VALUES (?, randomblob(?))");
db.exec("BEGIN");
for (let i = 0; i < 600000; i++) ins.run("t" + (i % 500), 1500 + (i % 7) * 200);
db.exec("COMMIT");
db.exec("DELETE FROM events WHERE id % 2 = 0");
db.exec("PRAGMA wal_checkpoint(TRUNCATE)");
let t = performance.now();
db.exec("PRAGMA wal_checkpoint(PASSIVE)");
db.exec("PRAGMA incremental_vacuum(20000)"); // what the hourly sweep runs
db.exec("PRAGMA wal_checkpoint(PASSIVE)");
console.log("one call:", Math.round(performance.now() - t), "ms");
t = performance.now();
for (let i = 0; i < 80; i++) db.exec("PRAGMA incremental_vacuum(250)");
console.log("80 x 250 pages:", Math.round(performance.now() - t), "ms total");Run it with node repro.mjs /tmp/repro.db. That builds a 1.6 GB database with 172k free pages.
Expected vs actual
Expected: / opens with an already-loaded list in about 0.2s. Database maintenance and other background work never block requests for more than about 100ms.
Actual, / (step A):
provider=claude-code 1.05 2.94 1.75 1.83 0.56 0.40 0.49 0.99 s (cold first call 1.42 s)
provider=codex 1.79 0.79 0.57 s
provider=nonexistent 0.10 0.51 0.20 0.34 0.13 0.15 0.19 0.11 0.21 0.12 s (no daemon RPC)
Actual, vacuum (step B, M-series Mac with SSD):
incremental_vacuum(20000) blocked for 1115 ms
80 x incremental_vacuum(250): 553 ms total (about 7 ms per chunk)
Actual, vacuum in production: all 32 hourly runs, Oct 7 01:02 to Oct 8 08:03 UTC.
10-07 02:02:51 durationMs 69355 cpuDurationMs 55016 PRAGMA incremental_vacuum(20000)
10-07 05:03:01 durationMs 65237 cpuDurationMs 50922
... (server restart 18:01)
10-07 19:02:34 durationMs 20206 cpuDurationMs 9014
10-08 08:03:29 durationMs 8980 cpuDurationMs 7456
total: 32 runs, 1,087 s wall, 891 s CPU; each frees about 80 MB of 4.2 GB free (about 51 more hours at this rate)
Each run lines up with a 9–11s Event loop stalled entry, for example 10-08 05:03:15 maxDelayMs 11601. That entry blames whatever request was in flight, such as bb-account.v1.waitForStatusChange, not the sweep.
Evidence
1. Hourly vacuum.
- The hourly
database-maintenancesweep (periodic-sweeps.ts#L205-L228) callsrunIncrementalVacuumwithMAX_PAGES = 20_000. That runs checkpoint, vacuum, checkpoint in one synchronous call. - Unlike the full-compaction branch (
#L232-L238), it never checksisDatabaseMaintenanceIdle. - Terminal disconnects: 159 of 703
Terminal session disconnectedlogs fall inside vacuum windows, which cover under 1% of the time.
2. Timeline builds (#4674, timeline.ts#L1010-L1030):
thr_46gxq5dyzhhad 254 logged builds totaling 123s. The worst was 7.1s and read 1,165 event rows (572 KB) for alatestpage that returns 3–75 rows.TRANSACTION DEFERREDhas 2,907 slow entries totaling 1,024s. Its max of 9,466ms equals the worst timeline build.- Timeline builds overlap 98 of the 162 event-loop stalls longer than 1s.
3. Background-task counts (events.ts#L2281):
- The query groups every background-task event per thread and calls
json_extracton each. - 6,423 runs took ≥100ms (p50 108, p99 186, max 564ms). That is 721s of wall time and 703s of CPU, so it is pure CPU.
- It runs a median of 144 times an hour, with a peak of 1,200.
- About 80% of calls bind a batch of thread IDs, meaning thread lists. Single-thread responses also call it.
4. Pruning: 3,787 slow resolved-items/usage advances totaling 530s. #5124 and #5115 on main reduce this, but the server has not been deployed with them yet.
5. /commands fan-out (projects.ts#L728). Three branches run in parallel:
- Provider commands (
native-roots.ts#L252): a plugin host RPC (resolveNativeRoots, cached after the first call), thenhost.list_commands. - Project skills (
workspace-skills.ts#L82):host.list_filesover.bb/skills, then onehost.read_fileperSKILL.md. - Shared skills:
host.list_skills.
The slowest branch is two serial trips warm and two cold. On a dev app with a 10-skill fixture, a single /commands call made 13 host RPCs on main and 2 with #5172. Server and daemon were local there, so it measures RPC count, not RTT.
6. Client (project-queries.ts#L302):
- Fine-pointer composers never prefetched the catalog. Cut per-thread-open requests behind the surfaces that need them (B9-B13, B16, C5) #1884 limited the focus prefetch to touch devices.
staleTime: 0makes each/open refresh in the background. That is intended, because it picks up newly written skills, and the cached list still shows instantly.
7. Daemon scan, timed locally against the claude-code roots:
resolveNativeRoots17–171ms.- Root resolution 1ms.
discoverProviderCommands22–157ms (26 commands from 9 roots). The first call is cold.
8. Server skill catalog (injected-skills.ts#L608): reading and SHA-256-hashing 48 server-side skills (78 files, 0.5 MB) took 14–24ms, timed on the production host.
How the server data was measured:
- Read-only aggregation of
/root/bb-server/data/logs/server.{50,51,52}.log, about 30h. - Page counts from opening
bb.dbread-only withnode:sqlite. - Nothing was restarted or written.
- Investigation thread: Investigate slow command lookup
What you ruled out
- Not network or proxy overhead: the same route without daemon RPCs returns in 0.1–0.5s.
- Not filesystem scanning: daemon scans take 20–160ms, and the server skill hash takes 15–25ms.
- Not lock contention: only the server process has
bb.dbopen, and vacuum CPU time is 70–85% of its wall time. - Not host CPU or disk saturation: both were low when sampled outside the vacuum windows.
- Not specific to this database: the standalone repro shows the same single-call block, just smaller.
- Not a duplicate:
- Event pruning stalls on busy workspaces because it waits for the whole workspace to be idle #5005 is about pruning waiting for idle.
- bb-app: event loop stalls (~2s) from sync SQLite / events truncation without yielding #3196 (closed) was about events truncation.
- Search and typeahead stall on full-text SQL, repeated file discovery, and slow mention providers #4413 is about full-text search and mention providers.
- Latest timeline page decodes every event of an open turn on each build, bypassing timelineWindowEventBudget #4674 covers row 2 only.
Suggested priority and effort
- Priority: high for remote or long-lived servers, where rows 1 and 2 cause stalls of seconds to a minute.
- Effort per row:
- Row 1 (Run the hourly database vacuum in chunks that yield to requests #5193): small. It vacuums in 256-page chunks and yields between them. A one-time offline
VACUUMwould also shrink this server's file from 8.1 GB to about 3.8 GB, which needs a maintenance window. - Row 2: bound the group-context read to the page window.
- Row 3: keep a per-thread count instead of grouping on every read.
- Row 4: deploy
main. - Rows 5–6: Load / commands when the desktop composer gets focus #5171 and Load project skills in one host round trip for / and thread start #5172.
- Row 1 (Run the hourly database vacuum in chunks that yield to requests #5193): small. It vacuums in 256-page chunks and yields between them. A one-time offline
AGENT GENERATED
Activity
bb-slop-cop commentedon Oct 8, 2026
🚨 SLOP COP 🚨 ·
new-issue-autopilotperfandhostlabels preserved.confirmed-repro.[-]Hourly incremental vacuum blocks the server event loop for 9–69s on large databases[/-][+]Slow / command lookup on remote servers: server stalls (hourly vacuum, timeline builds) dominate, not round trips[/+]Run the hourly database vacuum in chunks that yield to requests (#5193)
brsbl commentedon Oct 19, 2026
Row 6 (desktop prefetch): #5171 is closed. After #5777,
/commandsalso runs a liveprovider.list_commandsprobe. That probe can start a Claude Code CLI process per worktree cwd, cached for 2 minutes, so prefetching on desktop focus would add a CLI start to most thread opens. Prefetching on desktop needs a cheaper catalog path first: a server-side cache of live provider commands per host and provider, or a scan-only prefetch. The PR's focus flag would also need to reset on blur. Details are in the closing comment on #5171.Move archived threads to cold storage from Storage & retention, with …