Skip to content

Commit 8051465

Browse files
committed
perf(ccusage): use fast parsing for content usage lines
Allow the string-field parser to handle normal usage lines that include message.content. The local Claude data set has 162,838 usage lines and all of them include content, so the previous default sent effectively every usage line through JSON.parse before the lightweight object validation path. API error lines still fall back to the full JSON path because usage limit reset extraction needs message content, and malformed non-array content still falls back instead of being accepted by the fast parser. Reliable benchmark data is not included in this commit. An attempted hyperfine run was aborted after a concurrent Zig build started, and subsequent process checks still showed cmux at roughly 190-200% CPU. The previous measured JS blocks result remains 3.347s ± 0.044s from 6e876b6. Verified with pnpm run format, pnpm typecheck, pnpm --filter ccusage exec vitest run src/data-loader.ts, pnpm --filter ccusage run build, pnpm run test, and JS/Rust token-total parity checks for daily/session/monthly/weekly/blocks.
1 parent 6e876b6 commit 8051465

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

‎apps/ccusage/src/data-loader.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ function extractLastNumberField(line: string, field: string): number | undefined
372372

373373
function parseUsageDataLineFast(line: string, allowContent = false): UsageData | null {
374374
if (
375-
(!allowContent && line.includes('"content":')) ||
375+
(line.includes('"content":') && (!allowContent || !line.includes('"content":['))) ||
376376
line.includes('"isApiErrorMessage":true') ||
377377
line.includes('"cwd":null') ||
378378
line.includes('"sessionId":null') ||
@@ -455,7 +455,7 @@ function parseUsageDataLine(
455455
line: string,
456456
options?: { allowContentFast?: boolean },
457457
): UsageData | null {
458-
const fastData = parseUsageDataLineFast(line, options?.allowContentFast === true);
458+
const fastData = parseUsageDataLineFast(line, options?.allowContentFast !== false);
459459
if (fastData != null) {
460460
return fastData;
461461
}

0 commit comments

Comments
 (0)