@devries-cameron20 / t3code-1 / commits / abd47de64f
Fork 0

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

perf(usage): match transcript markers as bytes without a per-line latin1 string (#39659)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Neil Daquioag committed Nov 20, 2026 at 03:46 UTC abd47de64f17fdd141a0d0dfcdd710069d873b55
1 file changed +3 -9
apps/server/src/usage/usageTranscriptReader.ts
+3 -9
@@ -324,16 +324,10 @@ async function* readChunks(
324 }
325 }
326
327 -// Match markers in one latin1 alternation; one character per byte preserves exact ASCII offsets.
327 +// Match ASCII markers as raw bytes: UTF-8 cannot false-match them mid-sequence, and no line string is allocated.
328 export function transcriptLineGate(markers: readonly [string, ...string[]]) {
329 - if (markers.length === 1) {
330 - const marker = Buffer.from(markers[0]);
331 - return (line: Buffer) => line.includes(marker);
332 - }
333 - const pattern = new RegExp(
334 - markers.map((marker) => marker.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|"),
335 - );
336 - return (line: Buffer) => pattern.test(line.toString("latin1"));
329 + const needles = markers.map((marker) => Buffer.from(marker));
330 + return (line: Buffer) => needles.some((needle) => line.includes(needle));
331 }
332
333 /** Returns null on read failure; caching it as empty would hide usage until size/mtime changes. */