@devries-cameron20 / t3code Mirror · read-only / commits / 8dbf2621fa
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 03:15 UTC

perf(server): PR cache invalidation no longer waits on other projects' reads (1,163 ms → 0.12 ms median) (#30293)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Andrei committed Nov 6, 2026 at 12:24 UTC 8dbf2621fa1b2a201086d6b9535b385d7c3990a8
2 files changed +18 -1
apps/server/src/pullRequest/PullRequestReadCache.test.ts
+3
@@ -44,6 +44,9 @@ it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))("PR filesystem ca
44 const invalidate = yield* cache
45 .invalidate("pr")
46 .pipe(Effect.forkChild({ startImmediately: true }));
47 + // Another PR's invalidation does not wait on this read; this one's does.
48 + yield* cache.invalidate("other-pr");
49 + assert.isUndefined(invalidate.pollUnsafe());
50 yield* Deferred.succeed(release, undefined);
51 yield* Fiber.join(read);
52 yield* Fiber.join(invalidate);
apps/server/src/pullRequest/PullRequestReadCache.ts
+15 -1
@@ -26,6 +26,8 @@ import { detachStackFrame } from "../git/detachStackFrame.ts";
26 import { forkParked } from "../serverActivation.ts";
27
28 const CONCURRENT_READS = 512;
29 +/** Invalidation excludes only reads whose scopes share its stripe, not every PR read. */
30 +const SCOPE_STRIPES = 64;
31 // Entry filenames are the URI-encoded `<storeId>:<key>`; the scope revisions file has
32 // no store id. Effect before 4.1 wrote `<storeId><key>`, still pruned here.
33 const STORE_ID = "pr-v2";
@@ -87,6 +89,11 @@ export const make = Effect.gen(function* () {
89 const clock = yield* Clock.Clock;
90 let enabled = true;
91 const lock = yield* Semaphore.make(CONCURRENT_READS);
92 + const stripes = yield* Effect.forEach(Array.from({ length: SCOPE_STRIPES }), () =>
93 + Semaphore.make(CONCURRENT_READS),
94 + );
95 + const stripeOf = (scope: string) => (Hash.string(scope) >>> 0) % SCOPE_STRIPES;
96 + const revisionWrites = yield* Semaphore.make(1);
97 const digest = (key: string) =>
98 digester.digest(Digest.sha256, new TextEncoder().encode(key)).pipe(Effect.map(Hex.encode));
99 const revisions = yield* Cache.makeWith(
@@ -162,6 +169,12 @@ export const make = Effect.gen(function* () {
169 PersistenceError: () => read,
170 SchemaError: () => read,
171 }),
172 + // A read stores its result under the revisions it started with, so an invalidation of
173 + // one of its scopes must wait for it; reads of other scopes run on.
174 + (effect) =>
175 + [...new Set(scopes.map(stripeOf))]
176 + .toSorted((left, right) => left - right)
177 + .reduceRight((inner, stripe) => stripes[stripe]!.withPermits(1)(inner), effect),
178 lock.withPermits(1),
179 );
180 }, detachStackFrame),
@@ -182,7 +195,8 @@ export const make = Effect.gen(function* () {
195 return Effect.logWarning("PR cache disabled after clearing failed");
196 }),
197 Effect.uninterruptible,
185 - lock.withPermits(CONCURRENT_READS),
198 + revisionWrites.withPermits(1),
199 + (effect, scope) => stripes[stripeOf(scope)]!.withPermits(CONCURRENT_READS)(effect),
200 detachStackFrame,
201 ),
202 });