aft
aft copied to clipboard
aft_search with a path starts a synchronous git rev-parse on the OpenCode main thread
Summary
aft_search with a path argument can start a synchronous git rev-parse --show-toplevel on the OpenCode main thread for each call. The process start blocks the main thread. Under heavy disk writes, each start took up to 44.6 ms in our trace.
Location (v0.68.0, with the same code in v0.68.1 and in main at 22a1673f1)
packages/opencode-plugin/src/tools/permissions.ts:557-578:gitRootForNearestExistingParentcallsexecFileSync("git", ["rev-parse", "--show-toplevel"], …).:609-616:assertAftSearchExternalPermissionskips this call only when the target is inside a project root or worktree that is a git top level. In a session whose root is not a git top level (for example a parent folder of several repositories), or for a target outside the root, each search starts git.:647-650: the decision cache key contains the git root, so a cached decision also needs the git call first. On host version 2 the decision is not cached.- Published
dist/entry/server.js:47471(0.68.0) has the sameexecFileSynccall.
Measurement
We traced the main thread of a scratch OpenCode 2.4.2 server with the full plugin set. In 32 targeted searches, the trace shows 32 git rev-parse --show-toplevel starts on the main thread, one for each search. Bun starts the child with vfork, so the main thread waits until the child calls exec. During a period of heavy writes and deletes on the same disk, main-thread git starts took up to 44.6 ms each.
Request
- Cache the git top level for each directory. Remove the cache entry when a
.gitentry appears or disappears in that directory or above it. - Or find the top level without a process: walk up and look for
.git, asisGitTopleveldoes. Alternatively, resolve it in the Rust module or in a worker, not on the main thread.