Skip to content

Commit 0f019fd

Browse files
committed
Cache resolved VCS driver handles to avoid repeated repository detection
VcsDriverRegistry.resolve() calls detectRepository() which spawns 3 git processes (rev-parse --is-inside-work-tree, --show-toplevel, --git-common-dir). Since CheckpointStore calls resolve() for every git command (~6 per checkpoint capture), this added ~18 unnecessary process spawns per operation. Add an in-memory Map cache keyed on cwd + requestedKind so that once a repository is successfully detected for a given path, subsequent resolve() calls return the cached handle without re-running detection.
1 parent f800fca commit 0f019fd

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

apps/server/src/vcs/VcsDriverRegistry.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ export const make = Effect.fn("makeVcsDriverRegistry")(function* () {
4040
git,
4141
};
4242

43+
const resolveCache = new Map<string, VcsDriverHandle>();
44+
4345
const detectWithDriver = Effect.fn("VcsDriverRegistry.detectWithDriver")(function* (
4446
kind: VcsDriverKind,
4547
driver: VcsDriverShape,
@@ -78,12 +80,19 @@ export const make = Effect.fn("makeVcsDriverRegistry")(function* () {
7880

7981
const resolve: VcsDriverRegistryShape["resolve"] = Effect.fn("VcsDriverRegistry.resolve")(
8082
function* (input) {
83+
const requestedKind = input.requestedKind ?? "auto";
84+
const cacheKey = `${input.cwd}\0${requestedKind}`;
85+
const cached = resolveCache.get(cacheKey);
86+
if (cached) {
87+
return cached;
88+
}
89+
8190
const detected = yield* detect(input);
8291
if (detected) {
92+
resolveCache.set(cacheKey, detected);
8393
return detected;
8494
}
8595

86-
const requestedKind = input.requestedKind ?? "auto";
8796
return yield* unsupported(
8897
"VcsDriverRegistry.resolve",
8998
requestedKind === "auto" ? "unknown" : requestedKind,

0 commit comments

Comments
 (0)