Skip to content

Commit 4184949

Browse files
navidnadaliclaude
andcommitted
perf(server): background git work never loads a config snapshot
Git work marked as background now runs in its own small lane, so that background pull request discovery cannot hold up git status. That discovery reads config, and a read could load a config snapshot, or reload a stale one, in the background lane. A status refresh reading the same repository then waited for that load. Background reads now only reuse a current snapshot. Otherwise they run their own git command in their own lane, and loading is left to the other reads. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent d3e3810 commit 4184949

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

‎apps/server/src/vcs/GitVcsDriverCore.test.ts‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,43 @@ describe("config reads", () => {
904904
).pipe(Effect.provide(layerTest)),
905905
);
906906

907+
it.effect("loads a snapshot only for reads outside background work", () =>
908+
Effect.scoped(
909+
Effect.gen(function* () {
910+
const { driver, spawned } = yield* makeCountingDriver;
911+
const cwd = yield* makeTmpDir();
912+
yield* initRepoWithCommit(cwd);
913+
yield* git(cwd, ["config", "t3.value", "first"]);
914+
const read = driver.readConfigValue(cwd, "t3.value");
915+
const readInBackground = read.pipe(
916+
Effect.provideService(GitVcsDriver.BackgroundGitWork, true),
917+
);
918+
const getValue = ["config", "--get", "t3.value"];
919+
spawned.length = 0;
920+
921+
for (const _ of [1, 2, 3]) assert.equal(yield* readInBackground, "first");
922+
assert.deepStrictEqual(spawned, [getValue, getValue, getValue]);
923+
924+
assert.equal(yield* read, "first");
925+
assert.equal(yield* read, "first");
926+
spawned.length = 0;
927+
assert.equal(yield* readInBackground, "first");
928+
assert.deepStrictEqual(spawned, []);
929+
930+
yield* git(cwd, ["config", "t3.value", "second"]);
931+
assert.equal(yield* readInBackground, "second");
932+
assert.deepStrictEqual(spawned, [getValue]);
933+
spawned.length = 0;
934+
assert.equal(yield* read, "second");
935+
assert.equal(yield* read, "second");
936+
assert.isNotEmpty(spawned);
937+
spawned.length = 0;
938+
assert.equal(yield* readInBackground, "second");
939+
assert.deepStrictEqual(spawned, []);
940+
}),
941+
).pipe(Effect.provide(layerTest)),
942+
);
943+
907944
it.effect("reads what git config --get and git remote read", () =>
908945
Effect.scoped(
909946
Effect.gen(function* () {

‎apps/server/src/vcs/gitConfigSnapshot.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ import * as Duration from "effect/Duration";
88
import * as Effect from "effect/Effect";
99
import * as Exit from "effect/Exit";
1010
import * as FileSystem from "effect/FileSystem";
11+
import * as Option from "effect/Option";
1112
import * as Path from "effect/Path";
1213

13-
import type * as GitVcsDriver from "./GitVcsDriver.ts";
14+
import * as GitVcsDriver from "./GitVcsDriver.ts";
1415

1516
export interface GitConfigEntry {
1617
readonly origin: string;
@@ -516,6 +517,12 @@ export const makeGitConfigSnapshots = Effect.fn("makeGitConfigSnapshots")(functi
516517
const environment = gitConfigEnvironmentSignature(yield* HostProcess.Environment);
517518
if (environment === null) return null;
518519
const key = snapshotKey(cwd, environment);
520+
// Background work only reuses a current snapshot: a load in its small lane would hold up the
521+
// reads that wait for it.
522+
if (yield* GitVcsDriver.BackgroundGitWork) {
523+
const cached = Option.getOrNull(yield* Cache.getOption(snapshots, key));
524+
return cached !== null && (yield* isCurrent(cached)) ? cached.snapshot : null;
525+
}
519526
if (!(yield* Cache.has(snapshots, key)) && !isReadAgain(key)) return null;
520527
const cached = yield* Cache.get(snapshots, key);
521528
if (cached === null) return null;

0 commit comments

Comments
 (0)