The best way to control Claude Code, Codex and more from any computer or phone
perf(server): find in a long thread no longer re-parses every message on each keystroke (#20801)
Aaron Queen committed
Oct 18, 2026 at 13:16 UTC
f3bb914efbe02c0ce0c78313a3b70e6eccc968f2
2 files changed
+25
-1
apps/server/src/orchestration-v2/ThreadFind.test.ts
+22
@@ -456,6 +456,28 @@ describe("V2 thread find", () => {
456
}).pipe(Effect.provide(layerTest)),
457
);
458
459
+ it.effect("reuses parses across queries in a thread of a few hundred messages", () =>
460
+ Effect.gen(function* () {
461
+ const projection = yield* setup;
462
+ const total = 600;
463
+ yield* putItems(
464
+ Array.from({ length: total }, (_, i) => item(`long:${i}`, i + 1, `message ${i} needle`)),
465
+ );
466
+ const parse = vi.spyOn(ThreadFindText, "searchableMessageSegments");
467
+ try {
468
+ const first = yield* projection.searchThread({ threadId, query: "needle" });
469
+ assert.equal(first.totalMatches, total);
470
+ assert.equal(parse.mock.calls.length, total);
471
+ parse.mockClear();
472
+ const typed = yield* projection.searchThread({ threadId, query: "message 5" });
473
+ assert.equal(typed.totalMatches, 111);
474
+ assert.equal(parse.mock.calls.length, 0);
475
+ } finally {
476
+ parse.mockRestore();
477
+ }
478
+ }).pipe(Effect.provide(layerTest)),
479
+ );
480
+
481
it.effect("searches visible rendered messages and plans in canonical item order", () =>
482
Effect.gen(function* () {
483
const projection = yield* setup;
apps/server/src/orchestration-v2/ThreadFind.ts
+3
-1
@@ -263,8 +263,10 @@ export const makeThreadFind = Effect.fn("makeThreadFind")(function* (
263
});
264
});
265
});
266
+ // Each scan visits every message, so a cache smaller than the thread is cycled through and
267
+ // never hits. Real threads reach a few thousand messages of a few hundred characters.
268
const textCache = yield* Cache.make({
267
- capacity: 512,
269
+ capacity: 8192,
270
timeToLive: "1 minute",
271
lookup: (key: TextKey) => Effect.sync(() => parseText(key)),
272
});