Skip to content

perf(parser): single-pass field extraction in the large-line JSONL scanner#752

Merged
iamtoruk merged 1 commit into
mainfrom
perf/single-pass-scanner
Jul 19, 2026
Merged

perf(parser): single-pass field extraction in the large-line JSONL scanner#752
iamtoruk merged 1 commit into
mainfrom
perf/single-pass-scanner

Conversation

@iamtoruk

Copy link
Copy Markdown
Member

Follow-up to the desktop-slowness work: the large-line JSONL scanner was ~55% of warm-run CPU because parseLargeJsonl extracted each top-level field with an independent findObjectFieldValue walk — a multi-KB tool blob preceding the target keys got re-scanned up to ~8-9 times per assistant line.

  • New extractObjectFields: one walk over the object captures all requested fields (capture-or-skip, early exit when all found). Applied at the root (6 fields) and assistant-message (4 fields) levels. Exact semantics of the per-field walks preserved: raw-key comparison, first-match-wins on duplicate keys, identical behavior at truncated-key/unparseable-value failure points, same resync on stray content.
  • The old find* helpers remain — still used by usage/tool-block/user-text extraction paths.
  • Cache-load scoping was investigated and deliberately NOT done: every provider's incremental section (including durable OTel orphans) lives in the one session-cache file, so skipping the load on filtered runs would force cold re-parses and drop orphan history.

Evidence:

  • Synthetic 420MB corpus (large blobs preceding keys): cold parse 48.6s -> 23.3s (~2x).
  • Real 21MB session file, cold parse: 42.1s -> 17.4s (2.4x), output byte-identical (verified independently).
  • CPU profile: the per-field amplification frames drop to ~0%; remaining cost is the inherent single container scans.
  • 13 new tests (12 characterization pinned against the OLD implementation first, 1 whole-pipeline aggregate invariant); parser suites green.

@iamtoruk
iamtoruk merged commit 3472885 into main Jul 19, 2026
3 checks passed
@iamtoruk
iamtoruk deleted the perf/single-pass-scanner branch July 19, 2026 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant