perf: Optimize gt status from 13s to <1s (gt-zdtpw)
Key optimizations: - Use --no-daemon for bd commands to avoid daemon IPC overhead - Pre-fetch all agent beads in single query (ListAgentBeads) - Pre-fetch all hook beads in single query (ShowMultiple) - Pre-fetch all tmux sessions for O(1) lookup - Parallel rig processing with goroutines - Add --fast flag to skip mail lookups The main bottleneck was bd daemon communication timing out on stale daemon processes, causing 5+ second delays per rig. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
committed by
Steve Yegge
parent
6d1d1469b2
commit
22557e6917
@@ -218,7 +218,10 @@ func New(workDir string) *Beads {
|
||||
|
||||
// run executes a bd command and returns stdout.
|
||||
func (b *Beads) run(args ...string) ([]byte, error) {
|
||||
cmd := exec.Command("bd", args...)
|
||||
// Use --no-daemon for faster read operations (avoids daemon IPC overhead)
|
||||
// The daemon is primarily useful for write coalescing, not reads
|
||||
fullArgs := append([]string{"--no-daemon"}, args...)
|
||||
cmd := exec.Command("bd", fullArgs...)
|
||||
cmd.Dir = b.workDir
|
||||
|
||||
var stdout, stderr bytes.Buffer
|
||||
@@ -389,6 +392,55 @@ func (b *Beads) Show(id string) (*Issue, error) {
|
||||
return issues[0], nil
|
||||
}
|
||||
|
||||
// ShowMultiple fetches multiple issues by ID in a single bd call.
|
||||
// Returns a map of ID to Issue. Missing IDs are not included in the map.
|
||||
func (b *Beads) ShowMultiple(ids []string) (map[string]*Issue, error) {
|
||||
if len(ids) == 0 {
|
||||
return make(map[string]*Issue), nil
|
||||
}
|
||||
|
||||
// bd show supports multiple IDs
|
||||
args := append([]string{"show", "--json"}, ids...)
|
||||
out, err := b.run(args...)
|
||||
if err != nil {
|
||||
// If bd fails, return empty map (some IDs might not exist)
|
||||
return make(map[string]*Issue), nil
|
||||
}
|
||||
|
||||
var issues []*Issue
|
||||
if err := json.Unmarshal(out, &issues); err != nil {
|
||||
return nil, fmt.Errorf("parsing bd show output: %w", err)
|
||||
}
|
||||
|
||||
result := make(map[string]*Issue, len(issues))
|
||||
for _, issue := range issues {
|
||||
result[issue.ID] = issue
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// ListAgentBeads returns all agent beads in a single query.
|
||||
// Returns a map of agent bead ID to Issue.
|
||||
func (b *Beads) ListAgentBeads() (map[string]*Issue, error) {
|
||||
out, err := b.run("list", "--type=agent", "--json")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var issues []*Issue
|
||||
if err := json.Unmarshal(out, &issues); err != nil {
|
||||
return nil, fmt.Errorf("parsing bd list output: %w", err)
|
||||
}
|
||||
|
||||
result := make(map[string]*Issue, len(issues))
|
||||
for _, issue := range issues {
|
||||
result[issue.ID] = issue
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// Blocked returns issues that are blocked by dependencies.
|
||||
func (b *Beads) Blocked() ([]*Issue, error) {
|
||||
out, err := b.run("blocked", "--json")
|
||||
|
||||
Reference in New Issue
Block a user