Repository navigation
perf(lookup): date only candidate versions and stream derives through a buffer - #408
Merged
Merged
Conversation
… a buffer Cold lookups regressed after per-version dating (#342) asked Go's proxy, Maven POMs and NuGet registration pages about every version ever published, and stored each answer twice. Streamed derives read their bodies a byte at a time. - `Evaluator::candidates` names the versions policy can read a date or flag of: releases newer than the baseline evaluation compares against, wherever they sort, prereleases only when the current version is one or a `permitted` filter is set; every version when the baseline needs the catalog. The engine widens them per catalog key, and Go, Maven, NuGet registration pages and the versions host's tags describe only those; the rest are listed unchecked. A stored catalog view records the candidates it was read for and serves only lookups they cover. - Per-version date requests go through `Cached::uncached`: no HTTP table reads or writes (release-dates state keeps the answer), with host permits, cooldowns, 429 retries, operator mirrors and credentials. Maven POMs are now read through the mirror that serves the metadata, and a POM 429 leaves its version unchecked instead of dated as undated. - NuGet's registration index keeps each page's bounds; a page at or below every dependency's version is not read. - An undated mirror tag that is no candidate (a floating `v3` below `v4`) no longer sends the whole tag catalog to GitHub. - `json_document` reads through a 64 KiB buffer; the PEP 503 anchor scan is linear, and a private index page is sniffed so PEP 691 JSON no longer feeds the HTML scan. - SBOMs, image configs, Packagist, RubyGems and NuGet derive through typed structs; nodejs.org's index is a `node-lts` derived document; Helm entries reduce as they stream. - OSV listings are read concurrently and written in one transaction; tag objects likewise, per page. - `Groups::collect` returns at once without Pkl packages; advisory ranges parse once per evaluation; prerelease filters compute the release text only for a `regex:` filter. Every derived representation and the affected code-versioned states are bumped in tests/derived-versions.tsv and tests/state-versions.tsv.
sweepies
marked this pull request as draft
November 24, 2026 06:35
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
count-patchula | 6acbfb6 | Commit Preview URL Branch Preview URL |
Nov 24 2026, 06:35 AM |
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.
PR 1 of 3 in the performance regression series: cold lookups, streaming derives, and datasource and lookup CPU.
Why
Per-version dating (#342) made cold lookups ask Go's proxy, Maven POMs and NuGet registration pages about every version ever published, and stored each answer twice: once as
release-datesstate, once as an HTTP row. The measured cold run of a large Go monorepo went from about 12 s to 62–86 s, with ~34.6k requests (~33.8k toproxy.golang.org). The corpus cold run went from 6.7k to 23k requests. Streamed derives also read their bodies one byte at a time.What changes
Candidate-scoped dating, with #342's guarantee kept
Evaluator::candidates(dep)names the versions policy can read a date or flag of. These are the releases newer than the baselineevaluate_withcompares against, wherever they sort, so a patch on an older line counts like a new major. Prereleases are included only when the current version is one or apermittedfilter is set.extractVersionpattern, a runtime toolchain range, or a current value that is not a version (latest, a dist-tag).Client::with_candidates..info, Maven POM HEADs, NuGet registration pages and the versions-host tags only describe candidates. Everything else is listedunchecked, and policy never proposes those versions.catalogview records the candidates it was read for. It is reused only when those cover what the new lookup needs, so a dependency on an older version re-reads instead of finding its candidates unchecked.release-datesstill keeps every answer. A later lookup from an older baseline only dates the versions it adds.Date requests skip the HTTP table
Cached::uncached(method, url, accept). It never reads or writes thehttptable, so no writer transactions, and no npm packuments evicted from the 256 MiB budget.Status(429).registry_head, which skipped the mirror that servedmaven-metadata.xml. It also returnedOkon a 429, which got stored permanently as "dated, no date". POMs now go through the mirror, and a 429 leaves the version unchecked.release-datesis keyed by the entry that actually answered (Cached::plain_credential), mirrors included.NuGet: the registration index now keeps each page's
lower/upper. A linked page whoseupperis at or below the floor is not fetched. Pages without bounds are always read.versions host: an undated mirror tag that is not a candidate (a floating
v1/v3below the baseline) no longer throws away the whole mirror. An undated candidate tag still falls back to GitHub, as before.Streaming derives and CPU
json_documentreads through a 64 KiBBufReader. Trailing-data detection and stream-error propagation are unchanged, and tested.Anchorsscans in linear time: case-insensitive byte search, a cursor, and one drain per fed chunk.PYPI_INDEX_CATALOGlooks at the first non-whitespace byte.{is parsed as PEP 691 JSON, anything else is scanned as HTML. TheTeeis gone.ValueDOMs for SBOMs (noflatten, which would buffer everything), image configs, Packagist, RubyGems and NuGet.nodejs.org/dist/index.jsonis now anode-ltsderived document: just the newest LTS version.set_states. Tag objects are read concurrently and written once per GraphQL page.Groups::collectreturns immediately when the repository has no Pkl packages.Filter::asks_for_prereleasetakes the release text lazily and assumes the caller already matched the filter, so no secondmatches.Versions: every derived representation is bumped, because
derive.rsis in every row. So are the pull-token row (its file changed),catalog,catalog-controls,changelog,source-head,tag-catalog,tag-object,osv-advisory,extract,files,configandconfig-files. Docs updated:guide/sources.mdandinternals/cache.md.Behaviour notes for review
{but is not PEP 691 is now a document error instead of being retried as HTML. No HTML page starts with{, and a page that doesn't start with{could never parse as JSON, so every other page reads exactly as before.upper == current. Policy never reads the current version's yanked or deprecated flags; only versions above the baseline are reported as rejected.crates/engine/src/lib.rs(threading the candidates map intolookup_key, plus state version bumps) andcrates/notes(representation version bumps forced byderive.rs).Tests
Run on the remote VM:
cargo test --locked --no-fail-fast -p patchula-http -p patchula-datasource -p patchula-lookup -p patchula-config -p patchula-engine -p patchula-notes -p patchula-cache -p patchula-update -- --skip lockfiles::tests::real_: 70 binaries, 932 passed, 0 failed. This includes thederive_parityandstate_paritytests.cargo clippy --workspace --all-targets --locked -- -D warnings: clean.cargo fmt --all --check: clean.New tests: buffered
json_documentread sizes and mid-stream failure;Anchorsedge cases at every chunk size, bounded memory, and the JSON/HTML sniff;uncached(no cache reads or writes, 429 retry then error, mirror plus credentials); Go candidate dating and that it never touches the HTTP cache; Maven candidates, POM 429, and POM through the mirror; NuGet page skipping; versions-host floating tags; the catalog viewcoversreuse rule;Groups::collectshort-circuit; the candidate/full-catalog policy invariant;Candidateswiden/covers;node-lts.I did not re-measure live cold runs in this PR; the request and RSS numbers above are from before the fix.