Conversation
Identical bodies (memoized provider list, doc pages) were re-gzipped per request. WeakMap-keyed on the body identity so cache lives exactly as long as the body object; streams and no-transform paths unchanged.
Appends method/path/status/duration as JSONL to <data>/log/slow-requests.jsonl for requests slower than OPENCODE_SLOW_REQUEST_MS (default 250, 0 disables). Survives collector downtime; zero cost on the fast path.
Building this response walks the whole models.dev catalog through deep clones and per-model schema validation, then serializes ~5MB of JSON - ~700ms p50 on every web-UI page load. The four inputs (config, catalog, connected providers, credentials) are reference-stable between reloads, so memoize the encoded payload keyed on input identity and serve the cached bytes via handleRaw; any reload changes an input reference and invalidates instantly.
8081b22 to
4fbec70
Compare
The 1. Crash risk: 2. The memoization silently depends on an unstated invariant ( 3.
Minor: Also flagging scope: input-memoization fix, compression memoization, and a brand-new middleware are three separable changes; splitting would make bisecting a perf regression much easier. |
459f3a2 to
a316dcd
Compare
|
Thanks — working through these found a real bug. Responses point by point: 1. WeakMap crash — false positive, but worth stating why. The middleware bails first with 2. Your instability concern was correct and had already happened — fixed in 4de8e3a. I audited all four inputs: 3. slow-request-log (a316dcd): append is now fire-and-forget ( On scope: kept together deliberately — the slow-request log was added to measure exactly these two memoizations (it's how the 482ms |
|
Closing — these changes continue to be maintained in our fork. Thanks for the automated review feedback; feel free to reach out if upstream interest revives. |
Issue for this PR
Closes #44180
Related: #35897 (provider payload size — orthogonal cap/pagination request, but same pain)
Type of change
What does this PR do?
Three commits, all targeting the cost measured in #44129:
/providerpayload. The four inputs (config, models.dev catalog, connected providers, credentials) are reference-stable between reloads, so the encoded bytes are cached keyed on input identity (===on all four) and served viahandleRaw+HttpServerResponse.uint8Array. A config/auth/catalog reload swaps an input reference, which invalidates instantly. Responses are byte-identical (verified: 5,509,310 bytes, 193 providers, same shape before/after).WeakMapkeyed on the body object caches gzip/deflate results; the cache lives exactly as long as the body does. Streams and no-transform paths unchanged.<data>/log/slow-requests.jsonlaboveOPENCODE_SLOW_REQUEST_MS(default 250, 0 disables). Zero cost on the fast path. Useful for catching regressions like this one without a collector attached.How did you verify your code works?
Screenshots / recordings
N/A (server-side only).
Checklist