Repository navigation
perf(engine): resolve tag, ref and image digests side by side - #202
Conversation
The digest phase ran three waves one after another (refreshed mutable tags, other Git refs, image digests), and fresh_tag_digests sent its GraphQL chunks one at a time, then awaited each missing tag's REST fallback in turn. The three sets are independent and now resolve together, the chunks run under the GitHub governor, and each chunk's fallbacks run side by side. Warm lookup of grafana, mastodon and sentry: digest 4.9 s to 1.9 s, wall 7.4 s to 4.3 s, with an identical report.
|
¡Órale! Sombras sweep is done — review posted above. No bugs found; three P4 nits if you feel like polishing. 🎯 |
There was a problem hiding this comment.
¡Ja! Nice try hiding three waves in plain sight — but I pulled the whole thing apart and it holds. This is a clean concurrency refactor; I found no correctness, security or regression issues. Details below.
Findings
P0–P3: none.
P4 — cosmetic: fresh_tag_chunk's return type
Vec<((String, String), std::result::Result<String, Failure>)> restates TagDigests's element type. Returning TagDigests (collect resolved + the fallback stream into a BTreeMap) would let the outer function keep .flatten().collect() with less type noise. Pure style — take it or leave it.
P4 — contract note: duplicate keys now resolve nondeterministically
chunks.into_iter().flatten().collect() into a BTreeMap is last-write-wins; with buffer_unordered, completion order decides the winner, where the old serial loop overwrote deterministically. The only caller feeds BTreeSet-deduped keys, so this can only bite a future caller that passes duplicates spanning chunk boundaries. A one-line "keys must be unique" on the doc comment would close it.
P4 — note: fallback fan-out is concurrency², governor-gated
If GraphQL fails outright, every chunk falls back to REST at once: concurrency chunks × concurrency buffered fallbacks each (default 16 in-flight leaf futures, up to 10k at the max setting). They all queue on governor.acquire, so real request rate is unchanged — just worth being aware the governor, not buffer_unordered, is the actual limiter.
What I verified
- Partition is equivalent.
mutable_tagsuses the same predicate as the old filter, and the tworetains immediately before keepdigests/digest_keysdisjoint — so dropping the oldcontains_keyretain loses nothing, andself.digestssees exactly the same key set. - Progress accounting is identical. Stage total is still
digest_keys.len() + image_keys.len(); advances aremutable_tags.len()(bulk, as before) + 1 per ref + 1 per image. - Every key still produces an entry in
fresh_tag_chunk(resolved or fallback →Ok/Err), so no key silently vanishes and the bulkadvancestays honest. CREDENTIALEDisolation holds underjoin3.trackedscopes the task-local around eachpoll, so concurrenttrackedcalls inrefsandimagessee their own cells — no credential-flag leakage.sent/Spinnermutexes are never held across.await— lock, insert, drop.- Determinism preserved for replays:
mutable_tagsisBTreeSet-sorted, so chunk contents and GraphQL bodies are stable; cassette matching is content-based with ausedflag, so reordered requests still replay. - Shared client is safe:
fresh_tag_digestsandself.digestsboth funnel throughself.github's governor;buffer_unordered(0)can't happen (concurrencyis validated 1–100, defaults 4). - Malformed packages (
split_once('/')→continue) and GraphQL errors still fall back to the sameClient::digestREST path as before.
Verification
Read-through review; CI covers the tests (green except two pending jobs at review time).
A set keeps each key in one chunk, so concurrent chunks can never race to write the same entry; each chunk now returns TagDigests directly.
|
Thanks, Olivia. On the three P4s:
|
There was a problem hiding this comment.
¡Qué bien! You patched the holes before I could even re-jack in. 0dea8ef takes both P4s cleanly — one more pass and it's airtight.
Resolved findings
- P4 —
fresh_tag_chunk's return type: resolved. It now returnsTagDigestsdirectly;resolved.extend(fallback_stream)is safe becausemissingis disjoint fromresolvedby construction. - P4 — duplicate-key nondeterminism: resolved.
fresh_tag_digeststakes&BTreeSet<(String, String)>, so each key lives in exactly one chunk and chunk completion order can no longer pick a winner. The doc comment now states the set contract outright, which is even better than my "keys must be unique" suggestion. - P4 — fallback fan-out is governor-gated: accepted as intentional per your reply. The governor is the real rate limiter for every GitHub call;
buffer_unorderedonly bounds queued futures. 👍'd your explanation.
New-commit pass (0dea8ef)
- The engine's
partitionalready produced(BTreeSet, BTreeSet), so dropping theVecconversion is a pure cleanup —mutable_tags.len()still feeds the same bulkadvance. keys.iter().cloned().collect::<Vec<_>>()preserves theBTreeSetsort order, so chunk contents and the generated GraphQL bodies stay byte-deterministic for cassette replay.- Test update is faithful:
BTreeSet::fromcovers the multi-tag-single-repo path, and both the resolve and fallback branches still land in the returned map. - Only two call sites exist (
engine+ the test) and both compile against the new signature; no trait or other impl to chase.
No new findings.
Verification
Read-through review; CI covers the tests (jobs still pending on 0dea8ef at review time).
Follow-up to #201: after that change, the
digestphase is most of a warm lookup's wall time.What
The digest phase ran three waves one after another: refreshed mutable tags (
fresh_tag_digests), other Git refs, then image digests. Within the first wave,fresh_tag_digestssent its 64-tag GraphQL chunks one at a time, and after each one it awaited every missing tag's REST/commits/{ref}fallback in turn.join3.fresh_tag_digestsalways returns a result for every key it is given, so the REST set is exactly what it was before.fresh_tag_digestsruns its chunks under the GitHub governor (buffer_unordered(concurrency)). Each chunk starts its REST fallbacks as soon as its GraphQL query returns, and runs them side by side.Vecs. A closure over borrowed&[_]slices didn't type-check inside the server's boxedSendfutures ("FnOnceis not general enough").Measurements
Static x86_64 musl release binaries on the project's boat.dev VM, live warm lookups of grafana/grafana, mastodon/mastodon and getsentry/sentry with
examples/renovate-migration.pkl, five interleaved rounds:digestphaseThe JSON report is byte-identical across main before #201, #201 and this branch once timing, counter and metadata fields are removed.
Follow-ups
/commits/{tag}fallbacks that return422(for exampleactions/upload-artifact/commits/4.6.2,peter-evans/create-pull-request/commits/7.0.6) are never cached, so every warm run asks again. They now overlap instead of queueing, but each one still costs a round trip.digestis mostly one GraphQLFreshTagDigestsquery of about 1.3 s.