Skip to content

perf: cut repeated parsing and requests in the GitHub client and extraction - #407

Merged
sweepies merged 1 commit into
mainfrom
perf/github-and-extraction
Nov 24, 2026
Merged

sweepies merged 1 commit into
mainfrom
perf/github-and-extraction

Conversation

@sweepies

@sweepies sweepies commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

PR 3 of the performance series: the GitHub client, manager extraction and the engine's repository scan.

GitHub client

  • Governor: a GraphQL 200 is classified by its top-level errors alone. If the body's bytes contain neither errors nor a \u escape (which is the only other way JSON can spell that key), it isn't parsed under the in-flight permit. Otherwise a small map visitor reads message, documentation_url and errors and skips everything else without building a document. Any RATE_LIMITED or secondary-limit answer is still classified, including escaped keys and multi-MB bodies, and tests cover both.
  • identify: installation/repositories and viewer { databaseId } now go out together with tokio::join!. Every rule in the threat model is unchanged: both reads must succeed, and the contents probe still follows. A test proves the two reads overlap.
  • App::repository_id: single flight per (installation, repository). A failed read leaves the slot empty for the next caller.
  • Blobs: each GraphQL batch is cached in one SQLite transaction through the new Cache::http_put_many (Store::http_put now delegates to it).

Extraction

  • Shared YAML parse: Lines caches the file's serde documents and yaml_locations spans. Actions, GitLab CI, npm catalogs, Helm, pre-commit, Woodpecker, APM and Copier all share one parse, and the YAML family seeds Lines with the documents it already parsed. Actions keeps from_str's exact single-document behaviour.
  • Lazy locations: the YAML family reads a file's locations only when it takes something from that file (or fails on it). Files naming a Flux HelmRepository are still located eagerly, so the repository map is unchanged. When locating fails, the skip warning is emitted once per file.
  • YAML lockfiles: the YAML family no longer parses pnpm-lock.yaml or aube-lock.yaml. Selection is unchanged, so needs and the public verdict still read them.
  • Indexed lockfiles:
    • npm package-lock.json / bun.lock versions (first property wins, as with Object::get_*).
    • aube-lock.yaml key offsets, found in one pass with the same answers as text.find, which a test checks.
    • uv.lock / poetry.lock parsed once per extraction and indexed by PEP 503 name.
    • Cargo.lock crates.io releases indexed by name.
  • mise: the redirect check parses each config and the Cargo files once for every tool, instead of once per dependency.
  • Scanner: exclude is checked once per path and enabled managers are a bitset. Path predicates in gradle, cargo, nuget, maven and mise no longer allocate, and possible_source short-circuits. Regexes are hoisted into LazyLock. gradle_vars and runner_scope build their line tables once.

Engine

  • Repository view: shared_name is asked once per entry, and the final more pass is skipped when the chain already settled (the files are unchanged since it returned nothing).
  • Engine::config: finds its few modules in the tree slice instead of cloning every path and SHA into a map.
  • Files hash: streamed into SHA-256 (patchula_manager::hash_json). It produces the same bytes and the same hash, which a test checks.

Versioning

These states' hashed sources changed, so they are bumped: extract, files, config, config-files, catalog, catalog-controls, source-head, tag-catalog, tag-object, release-notes and changelog.

Some of these bumps, and the github-release-head derive bump, had to land outside this PR's planned files:

  • Outside the planned files: crates/engine/src/catalogs.rs (catalog), crates/datasource/src/github.rs (source-head, tag-catalog, tag-object, and the derive), crates/notes/src/{lib,releases}.rs and tests/derived-versions.tsv.
  • Why: every change under crates/github/src/ or crates/engine/src/lib.rs triggers them through the parity guard. The github-release-head derive is bumped only because its source file holds the bumped state constants.
  • Merge note: these lines are likely to conflict with the other PRs in this series, so the second PR to merge needs its parity hashes recomputed.

Tests

  • cargo test --locked --no-fail-fast -p patchula-github -p patchula-manager -p patchula-engine -p patchula-cache -p patchula-datasource -p patchula-notes -- --skip lockfiles::tests::real_ passes; tests/corpus-extraction.tsv has no diff.
  • cargo clippy --workspace --all-targets --locked -- -D warnings and cargo fmt --check are clean.

Follow-ups not done here

  • Cargo's prepare still clones each parsed Document once per extraction, and the workspace dependency Items once per manifest.

View guided diff Turn on auto-fix

@sweepies
sweepies marked this pull request as draft November 24, 2026 06:25
@cloudflare-workers-and-pages

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 de5266a Commit Preview URL

Branch Preview URL
Nov 24 2026, 06:25 AM

@sweepies
sweepies marked this pull request as ready for review November 24, 2026 06:45
…action

GitHub client:
- The governor classifies a GraphQL 200 by its top-level `errors` alone:
  a body whose bytes cannot spell that key (literally or through a `\u`
  escape) is not parsed under the in-flight permit, and one that can is
  scanned for the three classifying fields without building a document.
- `identify` reads the installation listing and the viewer together.
- `App::repository_id` is single flight per repository.
- GraphQL blob batches go to the cache in one write transaction each
  (`Cache::http_put_many`).

Extraction:
- Every manager reading a file as YAML shares one serde parse and one
  location parse through `Lines`; the YAML family locates a file only
  when it takes something from it, and skips YAML lockfiles.
- Lockfile lookups are indexed: npm's package-lock/bun.lock versions,
  aube-lock key offsets, uv/poetry locks parsed once per extraction,
  Cargo.lock releases by name.
- mise parses each configuration and the Cargo files once for every
  tool's redirect check.
- The scanner checks `exclude` once per path, keeps enabled managers as
  a bitset, and path predicates compare without allocating.
- The repository view asks `shared_name` once per entry and skips the
  final `more` pass when the chain settled; config modules are found in
  the tree without indexing every path; the files hash streams the JSON.

Code-versioned states whose hashed sources changed are bumped, as is
github-release-head, whose source holds the bumped source-head versions.
@sweepies
sweepies force-pushed the perf/github-and-extraction branch from de5266a to 674810f Compare November 24, 2026 18:51
@sweepies
sweepies merged commit 5ef4a68 into main Nov 24, 2026
14 checks passed
@sweepies
sweepies deleted the perf/github-and-extraction branch November 24, 2026 18:58
@sweepies-ops sweepies-ops Bot mentioned this pull request Nov 24, 2026

This branch was successfully deployed

1 active deployment
docs-preview — 674810f5 Deployed Nov 24, 2026 by sweepies via Docs: preview #47
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