Skip to content

perf(engine): resolve tag, ref and image digests side by side - #202

Merged
sweepies merged 2 commits into
mainfrom
perf/digest-wave
Nov 8, 2026
Merged

sweepies merged 2 commits into
mainfrom
perf/digest-wave

Conversation

@sweepies

@sweepies sweepies commented Nov 8, 2026 •

Copy link
Copy Markdown
Owner

Follow-up to #201: after that change, the digest phase 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_digests sent 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.

  • The engine partitions the keys up front (mutable tags vs other refs) and resolves the three sets together with join3. fresh_tag_digests always returns a result for every key it is given, so the REST set is exactly what it was before.
  • fresh_tag_digests runs 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.
  • The chunks are owned Vecs. A closure over borrowed &[_] slices didn't type-check inside the server's boxed Send futures ("FnOnce is 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:

#201 this PR
digest phase ~4.9 s ~1.9 s
wall ~7.4 s ~4.3 s

The JSON report is byte-identical across main before #201, #201 and this branch once timing, counter and metadata fields are removed.

Follow-ups

  • REST /commits/{tag} fallbacks that return 422 (for example actions/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.
  • What's left of digest is mostly one GraphQL FreshTagDigests query of about 1.3 s.

View guided diff Turn on auto-fix

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.
@olivia-colomar-app

olivia-colomar-app Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

¡Órale! Sombras sweep is done — review posted above. No bugs found; three P4 nits if you feel like polishing. 🎯

@olivia-colomar-app olivia-colomar-app Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

¡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_tags uses the same predicate as the old filter, and the two retains immediately before keep digests/digest_keys disjoint — so dropping the old contains_key retain loses nothing, and self.digests sees exactly the same key set.
  • Progress accounting is identical. Stage total is still digest_keys.len() + image_keys.len(); advances are mutable_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 bulk advance stays honest.
  • CREDENTIALED isolation holds under join3. tracked scopes the task-local around each poll, so concurrent tracked calls in refs and images see their own cells — no credential-flag leakage.
  • sent/Spinner mutexes are never held across .await — lock, insert, drop.
  • Determinism preserved for replays: mutable_tags is BTreeSet-sorted, so chunk contents and GraphQL bodies are stable; cassette matching is content-based with a used flag, so reordered requests still replay.
  • Shared client is safe: fresh_tag_digests and self.digests both funnel through self.github's governor; buffer_unordered(0) can't happen (concurrency is validated 1–100, defaults 4).
  • Malformed packages (split_once('/') → continue) and GraphQL errors still fall back to the same Client::digest REST 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.
@sweepies

sweepies commented Nov 8, 2026

Copy link
Copy Markdown
Owner Author

Thanks, Olivia. On the three P4s:

  • Return type / duplicate keys: I took both together in the latest commit. fresh_tag_digests now takes a &BTreeSet<(String, String)>, so keys are unique by construction and the result can't depend on which chunk finishes first. fresh_tag_chunk returns TagDigests. The engine already had a set, so it drops its Vec conversion.
  • Fallback fan-out: this is intentional. The governor sets the real request limit for every GitHub call, and buffer_unordered only bounds the futures waiting on it, as elsewhere in the engine.

@olivia-colomar-app olivia-colomar-app Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

¡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 returns TagDigests directly; resolved.extend(fallback_stream) is safe because missing is disjoint from resolved by construction.
  • P4 — duplicate-key nondeterminism: resolved. fresh_tag_digests takes &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_unordered only bounds queued futures. 👍'd your explanation.

New-commit pass (0dea8ef)

  • The engine's partition already produced (BTreeSet, BTreeSet), so dropping the Vec conversion is a pure cleanup — mutable_tags.len() still feeds the same bulk advance.
  • keys.iter().cloned().collect::<Vec<_>>() preserves the BTreeSet sort order, so chunk contents and the generated GraphQL bodies stay byte-deterministic for cassette replay.
  • Test update is faithful: BTreeSet::from covers 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).

@sweepies
sweepies merged commit 20136ad into main Nov 8, 2026
11 checks passed
@sweepies
sweepies deleted the perf/digest-wave branch November 8, 2026 18:26
@sweepies-ops sweepies-ops Bot mentioned this pull request Nov 8, 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