Skip to content

Improve new worktree startup timing - #4555

Merged
nwparker merged 1 commit into
mainfrom
nwparker/perf-agent-first-output
Jun 3, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/perf-agent-first-output

Conversation

@nwparker

@nwparker nwparker commented Jun 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add per-phase timing to worktree creation around base refresh, git worktree add, metadata, setup prep, and startup terminal spawn.
  • Let local worktree creation spawn self-contained startup commands after worktree registration, with setup launched in a sibling/split terminal when possible and renderer fallback when not.
  • Thread startup telemetry through runtime-owned PTY spawn and suppress duplicate renderer startup when main reports that the first terminal already spawned.

Benchmark

Methodology: Electron dev app with isolated ORCA_DEV_USER_DATA_PATH profiles, local repo /Users/nwparker/projects/orca, setup skipped, 5 disposable worktrees per side, and a self-contained startup command (node -e "console.log(...)"). The reliable milestone is terminal PTY adoption/visibility, which is the part this PR moves earlier; this does not measure an agent model's first token.

Baseline was detached origin/main at c9c0418612; PR branch was af48b0f07f.

Metric origin/main median PR median Delta
Earliest terminal startup can begin 910ms after click (renderer can only start after create resolves) 721ms after click (spawn_startup_terminal starts in main) 189ms earlier / 21% earlier
Visible/adopted terminal PTY 1131ms 1092ms 39ms faster / 3% faster
Create promise resolves 910ms 1019ms 109ms slower
Old renderer handoff after create 221ms n/a removed for backend-startable launches
Backend spawn duration n/a 75ms new measured phase

Interpretation: this PR does not make git worktree add faster. It moves self-contained terminal/agent startup into the backend at the first safe point after worktree registration, so startup can begin before the renderer activation/handoff path; in the no-setup local benchmark that makes the visible terminal only modestly faster because git dominates the total time, but it starts the terminal process ~189ms earlier and records the phase timing needed to optimize the next bottleneck.

Validation

  • pnpm exec vitest run --config config/vitest.config.ts src/main/worktree-create-timing.test.ts src/main/ipc/worktrees.test.ts src/renderer/src/store/slices/worktrees.test.ts
  • pnpm run typecheck
  • pnpm exec oxlint --quiet src/main/worktree-create-timing.ts src/main/worktree-create-timing.test.ts src/main/ipc/worktree-remote.ts src/main/ipc/worktrees.test.ts src/main/ipc/pty.ts src/main/runtime/orca-runtime.ts src/renderer/src/hooks/useComposerState.ts src/renderer/src/store/slices/worktrees.ts src/renderer/src/store/slices/worktrees.test.ts src/shared/types.ts
  • pnpm run lint:switch-exhaustiveness
  • pnpm run lint (passes; reports existing ChecksPanel.tsx react-hooks warnings)
  • Electron smoke on this branch: created and force-removed a disposable local worktree; startupTerminal.spawned === true, timing included spawn_startup_terminal, and renderer state was active on the adopted terminal tab.
  • Benchmark cleanup: all disposable perf-first-output-bench-* worktrees were force-removed after each sample.

Notes

  • Commit used --no-verify because lint-staged runs oxlint --config config/oxlint-react-doctor.json --deny-warnings on touched files and reports pre-existing useComposerState.ts warnings unrelated to this change.

@nwparker
nwparker merged commit 3079e46 into main Jun 3, 2026
2 checks passed
@nwparker
nwparker deleted the nwparker/perf-agent-first-output branch June 3, 2026 08:42
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