Skip to content

th-2e1ad2: batch-load pearl labels — session start 5.7s → 0.7s#243

Merged
brentrager merged 1 commit into
mainfrom
th-2e1ad2-batch-labels
Jul 22, 2026
Merged

th-2e1ad2: batch-load pearl labels — session start 5.7s → 0.7s#243
brentrager merged 1 commit into
mainfrom
th-2e1ad2-batch-labels

Conversation

@brentrager

Copy link
Copy Markdown
Contributor

Problem

th prime runs on every SessionStart and calls th pearls ready5.7s against a 1200-pearl store. Root cause: ready/list/blocked/search/due_scheduled returned the matching pearls in one query, then fired one more Dolt query per pearl to load labels (N+1). Each Dolt call cold-boots (~140ms), so th agent list (1 query) is 0.5s while th pearls list (1+N) is 4.7s on the same DB.

Fix

attach_labels(Vec<Pearl>) — a single SELECT pearl_id, label FROM pearl_labels WHERE pearl_id IN (…), grouped in Rust (order preserved, label-sorted). Wired into all five list-style reads. The single-pearl get path keeps load_pearl_with_labels (1 pearl = 1 query, nothing to batch).

Measured

th pearls ready against the real 1200-pearl store: 5.7s → ~0.7s warm.

Tests

list_batch_loads_labels_per_pearl — asserts each pearl gets exactly its own labels (no cross-contamination), unlabelled pearls stay empty, label order preserved. Full smooth-pearls suite green.

🤖 Generated with Claude Code

@changeset-bot

changeset-bot Bot commented Jul 22, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ec90e65

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@smooai/smooth Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@brentrager
brentrager enabled auto-merge (squash) July 22, 2026 16:52
@brentrager
brentrager force-pushed the th-2e1ad2-batch-labels branch from a87164f to 90e7a7f Compare July 22, 2026 16:57
…tart 5.7s

`th prime` (SessionStart) runs `th pearls ready`, which returned ~40 open pearls
then fired one more Dolt query PER pearl to load labels. Each Dolt call
cold-boots (~140ms), so list-style reads cost 1 + N round-trips — `th agent list`
(1 query) 0.5s vs `th pearls list` (1+N) 4.7s against the same DB.

Add `attach_labels(Vec<Pearl>)`: one `SELECT ... WHERE pearl_id IN (...)` groups
labels in Rust, order preserved, label-sorted. Wire it into ready/list/blocked/
search/due_scheduled (the single-pearl get path keeps load_pearl_with_labels).

Measured on the real 1200-pearl store: `th pearls ready` 5.7s -> 0.7s warm.
Regression test asserts per-pearl labels with no cross-contamination.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ZctFb4oiWoJraHN2db1nX
@brentrager
brentrager force-pushed the th-2e1ad2-batch-labels branch from 90e7a7f to ec90e65 Compare July 22, 2026 22:39
@brentrager
brentrager merged commit 72ed3cc into main Jul 22, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant