Repository navigation
Conversation
…issue chattymin#337) ISO8601Parser built a new ISO8601DateFormatter on every call, on the assumption that it ran rarely. It runs once per assistant line of every local session log, so on a large history formatter construction dominated the cold scan. Keep one fractional and one plain formatter behind a lock, the pattern LocalAdditionalUsageProvider already uses; parsing behaviour, including the fractional-width fallback, is unchanged.
…hattymin#337) The cache keyed blobs on (path, mtime, size), so the active session file, which changes on every refresh and can reach hundreds of MB, was re-read from byte 0 each time and three passes per refresh did it repeatedly. Blobs for Claude now record the offset of the last complete line. When a file only grew, the cache parses the tail from that offset and merges it with the cached entries (dedupKeepMax, since a streaming turn repeats its id across the boundary). A shrink, a same-size change, a missing offset (older cache files), or a changed fingerprint of the 256 bytes before the offset (a rewritten prefix) falls back to a full parse. A trailing line with no newline is parsed but left out of the offset, so it is read again once complete. Parsing streams 1 MB chunks through the existing line reader (generalized from the Codex one) instead of loading the file as a String. The offset lives in usage-cache.json, which the isolated support folder already covers for tests. Upstream PR chattymin#338 (unmerged) was used as a reference; the fingerprint, the chunked reader and the tests are this fork's. Benchmark (PTB_BENCH=1 ClaudeScanBenchmarkTests, 102 MB synthetic log, 39,000 usage lines), before -> after: cold parse 11,376 ms -> 3,289 ms refresh after 1 append 11,295 ms -> 118 ms unchanged refresh 75 ms -> 69 ms peak footprint (cold) 219 MB -> 80 MB Tests: tail-only reads (bytes observed), a streaming turn across the boundary, a half-written last line, truncation, same-size rewrite, a rewritten prefix that grew, incremental result equal to a full parse, no duplicate accumulation in the stored blob, and legacy blobs without an offset. Each guard was checked by mutating the code it protects.
…eam chattymin#333) Claude Code can write <synthetic> assistant records whose usage is all zero even when no request ran. The store already ignored them for display (totalTokens > 0), but activeBlock still let them create a 0-token block or pull the block start earlier, lowering tokens per minute. Filter them out of the block window. Only the reader half of chattymin#333 is ported; the store half was already here.
The fork priced Sonnet 5.5 cache reads at $0.20/MTok; upstream changed it to $0.10. Checked against the primary source on 2026-10-16, https://platform.claude.com/docs/en/about-claude/pricing: Sonnet 5.5 cache hits are $0.10/MTok (cache hits on Opus 5.5 and Sonnet 5.5 are 0.05x base input). Every other Claude row in the table matches that page. Cache blobs keep raw token counts and are priced at aggregation, so no cache version bump is needed. Only the pricing part of upstream dc6de41 is ported.
The cost-state format is confirmed from real Claude Code transcripts, but the ledger covers only the run since its startTime and includes calls the file does not log (subagent transcripts carry no ledger). Spreading the last ledger over every entry, as upstream does, would erase earlier entries' cost and double-count subagents. Hold the port and record the evidence.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SP4 batch B: Claude log scan performance and usage accuracy. Branched from
mainafter #20; it relies on #20's isolated support folder for tests.(path, mtime, size), so the active session file, which changes on every refresh and can reach hundreds of MB, was re-read from byte 0 each time. A refresh makes up to three passes, so it did this repeatedly.dedupKeepMaxis applied to the merge, because a streaming turn repeats its id across the boundary.String.ISO8601Parserno longer builds a formatter on every call. It runs once per assistant line, and that construction dominated the cold scan. One formatter pair is now shared behind a lock (the patternLocalAdditionalUsageProvideralready uses).usage-cache.json, which Isolate test runs from every app-support store, plus the SP4 port spec and plan (SP4 batch A) #20 already isolates underAppEnv.supportDirectory()for tests.<synthetic>records no longer create an active block or pull its start earlier. The store-side filter was already here.dc6de41).ModelPricingmatches that page.Benchmark (chattymin#337)
PTB_BENCH=1 swift test --filter ClaudeScanBenchmarkTests, with a 102 MB synthetic session log (117,000 lines, 39,000 usage lines), same harness on both sides:main)Held: chattymin#318 (Claude-reported
cost-state)The record format is confirmed from real Claude Code transcripts on this machine (read-only, structure only):
type:"cost-state", withstartTimein epoch milliseconds;modelUsage.<model>.{inputTokens, outputTokens, cacheReadInputTokens, cacheCreationInputTokens, costUSD};costUSDvalues sum tototalCostUSD.Its meaning does not match upstream's assumption:
startTime, not the whole file. 13 of the 22 files with a ledger contain earlier entries (in one, 6,661 of 6,737). Several have an emptymodelUsage.Spreading the last ledger over every entry of the file by tokens, as upstream does, would erase the earlier entries' cost and double-count subagent cost. The fork already prices the Claude 5 family, so the gain is small. I did not port it; the spec and plan record the evidence. This is a decision for the maintainers.
Type of change
UI changes
None.
Verification
./scripts/test-gate.sh:Executed 2036 tests, with 12 tests skipped and 0 failures (0 unexpected)✓ 게이트 통과 — 로직 코어 라인 커버리지 93.98% >= 75%SessionKeySettingsRenderingTests:46, the scroll timing that batch F'sb716054addresses. The third run was clean, and the test passed 5/5 alone. The machine was under heavy WindowServer andcodesignload from other work.ClaudeIncrementalParseTests, 9):ISO8601ParserSharingTests: every timestamp format still parses, and 2,000 concurrent calls agree.Hotspot files
None (
LocalUsageCache,LocalUsageReader,Models(ISO8601Parseronly),ModelPricing).UsageStore.swiftis not touched.Not addressed
Checklist
swift buildandswift testpass locally