From 124cc33745b34972499b774ddc1841fa8d18b682 Mon Sep 17 00:00:00 2001 From: harshitsinghbhandari <24b4506@iitb.ac.in> Date: Sun, 29 Mar 2026 18:28:04 +0530 Subject: [PATCH] perf(cli): parallelize I/O calls in 'ao session ls' for faster listing --- packages/cli/src/commands/session.ts | 33 +++++++++++++++++++--------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/packages/cli/src/commands/session.ts b/packages/cli/src/commands/session.ts index 0c6cf88d5..861c5d5f1 100644 --- a/packages/cli/src/commands/session.ts +++ b/packages/cli/src/commands/session.ts @@ -51,17 +51,30 @@ export function registerSession(program: Command): void { continue; } - for (const s of projectSessions) { - // Get live branch from worktree if available - let branchStr = s.branch || ""; - if (s.workspacePath) { - const liveBranch = await git(["branch", "--show-current"], s.workspacePath); - if (liveBranch) branchStr = liveBranch; - } + // Pre-fetch all branches and activities in parallel + const branches = await Promise.all( + projectSessions.map(async (s) => { + if (s.workspacePath) { + return git(["branch", "--show-current"], s.workspacePath).catch(() => null); + } + return null; + }), + ); - // Get tmux activity age - const tmuxTarget = s.runtimeHandle?.id ?? s.id; - const activityTs = await getTmuxActivity(tmuxTarget); + const activities = await Promise.all( + projectSessions.map((s) => { + const tmuxTarget = s.runtimeHandle?.id ?? s.id; + return getTmuxActivity(tmuxTarget).catch(() => null); + }), + ); + + for (let i = 0; i < projectSessions.length; i++) { + const s = projectSessions[i]; + const liveBranch = branches[i]; + const activityTs = activities[i]; + + // Priority: live branch from workspace > metadata branch > empty string + let branchStr = (s.workspacePath && liveBranch) ? liveBranch : (s.branch || ""); const age = activityTs ? formatAge(activityTs) : "-"; const parts = [chalk.green(s.id), chalk.dim(`(${age})`)];