Skip to content

perf(http): large documents are derived as they arrive - #288

Merged
sweepies merged 3 commits into
mainfrom
perf/streaming-derive
Nov 13, 2026
Merged

sweepies merged 3 commits into
mainfrom
perf/streaming-derive

Conversation

@sweepies

@sweepies sweepies commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

Consult 7, PR 11. A cold lookup of a large repository held each registry document whole before deriving from it: npm packuments run to tens of megabytes (vite 39 MB, renovate 75 MB), and a cold grafana lookup peaked at about 700 MB. That peak is the first suspect for the memory growth in issue #193.

Streaming derivation

  • Transport gains send_streaming, returning the status, headers and a body stream. Its default wraps a buffered send into one chunk, so fakes and replay cassettes work unchanged; the network client streams bytes_stream().
  • conditional::derive feeds chunks to its blocking worker through a bounded channel (four chunks) and parses with serde_json::Deserializer::from_reader plus end(), which rejects trailing content as before. The raw document is never held whole. Every Derived transform reads from io::Read: JSON Lines through BufRead, YAML through serde_yaml_ng::from_reader; the HTML-or-JSON sniffing transform buffers locally.
  • Only successful derived responses stream. Redirects, 429s, retries and 304s stay buffered for the loop that inspects them. Cancellation still aborts, a mid-stream transport error surfaces as before, and nothing is cached on failure.
  • A streamed response holds its host permit until the body is read, so in-flight bodies count against the host limit; buffered derives keep their separate bound of four.

Host limit 16 → 32. Holding a permit through the body read serialises a host at 16 (cold grafana about 16 s). At 32 wall time is back to today's and memory stays near 165 MB; 64 bought nothing more. defaultHostConcurrency default, reference/settings.mdx, internals/cache.md. GitHub's API keeps its own cap: a CLI run uses the api.github.com host limit when set, otherwise the default capped at 16 (unchanged from before); the server keeps 4.

Proof

  • derive_parity (datasource and notes) runs every Derived transform over all 294 fixture bodies, whole and in 997-byte and tiny chunks: identical output. With PATCHULA_PARITY_DOCS it also covers the four captured packuments of benchmarks:catalogs (vite, typescript, renovate, effect); identical in release mode.
  • benchmarks:catalogs replay digest is identical before and after.
  • No transcript changes. New tests cover parsing exactly one JSON document, 1-byte chunks, cancellation and a stream error mid-body.

Measured (VM, musl release, cold cache, co-tenant load so wall times are conservative):

wall peak RSS
grafana, before (16) 12.4–12.8 s 532–808 MB (~680)
grafana, after (32) 11.7–18.5 s (about 10 s in idle probes) 160–167 MB
sentry, before (16) 8.7–10.3 s 154–165 MB
sentry, after (32) 9.1–11.4 s 119–124 MB

View guided diff Turn on auto-fix

Known limits, not regressions: Helm indexes (YAML), the PyPI simple-index fallback and image digests still buffer their whole body, as before.

sweepies and others added 2 commits November 13, 2026 00:06
A derived read used to buffer the whole response on the engine side before
its compaction ran, so one cold large repository peaked near 700 MB.
Successful derived answers now stream decoded chunks through a bounded
channel into the blocking derive worker, which parses each document with a
reader (serde_json::Deserializer::from_reader, BufRead, serde_yaml_ng
from_reader) instead of a slice. The request's host permit is held until
its body is read, so in-flight bodies stay inside the per-host limit;
buffered derives keep their own four-job bound.

Derived outputs are byte-identical (a parity test runs every derive over
every fixture body and the captured catalog documents under several
chunkings), transcripts and cache semantics are unchanged, and statuses
the loop inspects — redirects, throttles, retries, 304 — stay buffered.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Streaming derivation holds a host permit until its body is read, which
serialises download and parse under one slot: at the old limit of 16 a
cold grafana lost wall time even though peak RSS fell from ~680 MB to
~160 MB. Measured at 16, 32 and 64, 32 restores parity with the old
wall (~13 s) at ~165 MB peak, and 64 buys nothing further. GitHub's
client keeps its own governor.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
count-patchula 1fbda9b Commit Preview URL

Branch Preview URL
Nov 13 2026, 12:29 AM

…t rises

A token run sized GitHub's governor from the default host limit, so
raising that to 32 doubled the CLI's GitHub concurrency. GitHub now takes
its own host limit when one is set, otherwise the default capped at 16.
@sweepies
sweepies merged commit 4b19ce4 into main Nov 13, 2026
13 checks passed
@sweepies
sweepies deleted the perf/streaming-derive branch November 13, 2026 00:35
@sweepies-ops sweepies-ops Bot mentioned this pull request Nov 13, 2026
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