perf: speed up new-session creation #256

Merged
dries merged 1 commit from perf/fast-session-create into main 2026-07-08 23:00:47 +02:00
Owner

Summary

Creating a new session took multiple seconds. Two causes fixed:

  • Backend happy path: Adapter.CreateSession always ran an uncached lsof scan on every create (full socket scan + one lsof -p fork per opencode PID on macOS). Now it reads the cached port map first and only falls back to the fresh scan on a miss (just-launched process the cache hasn't seen).
  • Frontend cold path: the post-launch retry loop slept a fixed 1500ms before the first retry. Local opencode binds well under a second, so it now polls fast up front ([400,600,800,1200,1500,2000,3000]), catching a quick boot in ~400ms while keeping the same ~9.5s total budget.

Testing

  • Added TestCreateSession_CachedPortSkipsFreshScan (cache hit must not re-scan).
  • Updated stale retry-count assertion (5 -> 7).
  • make lint, go test ./..., pnpm test all pass.
## Summary Creating a new session took multiple seconds. Two causes fixed: - **Backend happy path:** `Adapter.CreateSession` always ran an uncached `lsof` scan on every create (full socket scan + one `lsof -p` fork per opencode PID on macOS). Now it reads the cached port map first and only falls back to the fresh scan on a miss (just-launched process the cache hasn't seen). - **Frontend cold path:** the post-launch retry loop slept a fixed 1500ms before the first retry. Local opencode binds well under a second, so it now polls fast up front (`[400,600,800,1200,1500,2000,3000]`), catching a quick boot in ~400ms while keeping the same ~9.5s total budget. ## Testing - Added `TestCreateSession_CachedPortSkipsFreshScan` (cache hit must not re-scan). - Updated stale retry-count assertion (5 -> 7). - `make lint`, `go test ./...`, `pnpm test` all pass.
perf: speed up new-session creation
All checks were successful
CI / Backend (pull_request) Successful in 4m21s
CI / Frontend (pull_request) Successful in 4m49s
CI / Build Desktop (macOS arm64) (pull_request) Successful in 5m20s
CI / Build (pull_request) Successful in 4m4s
CI / Coverage Ratchet (pull_request) Successful in 7m40s
CI / Playwright E2E (pull_request) Successful in 6m15s
CI / Semantic Tag (pull_request) Has been skipped
7a8f50ae8f
Reuse the cached opencode port map on the create happy path instead of
always running a fresh uncached lsof scan; only fall back to the fresh
scan on a cache miss (just-launched process). Poll faster up front in
the post-launch retry loop so a quick local boot is caught in ~400ms
instead of 1.5s, keeping the same ~9.5s total budget.

Coverage ratchet: pass

Suite Baseline This PR Δ
go 71.50% 71.50% +0.00
frontend 60.83% 60.83% +0.00

Tolerance: -0.1%. Baseline stored on gh-pages.

<!-- coverage-ratchet --> ### Coverage ratchet: ✅ pass | Suite | Baseline | This PR | Δ | | |---|---|---|---|---| | go | 71.50% | 71.50% | +0.00 | ✅ | | frontend | 60.83% | 60.83% | +0.00 | ✅ | _Tolerance: -0.1%. Baseline stored on `gh-pages`._
dries merged commit 1b76f10273 into main 2026-07-08 23:00:47 +02:00
Sign in to join this conversation.
No description provided.