Skip to content

perf(install): fetch monorepo subdirectory deps as pin trees + exact cone blobs, in process - #5377

Merged
Daniel Meppiel (danielmeppiel) merged 15 commits into
mainfrom
perf/inprocess-sparse-fetch
Nov 25, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 15 commits into
mainfrom
perf/inprocess-sparse-fetch

Conversation

@danielmeppiel

@danielmeppiel Daniel Meppiel (danielmeppiel) commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Description

A monorepo subdirectory dependency (owner/repo/path#ref) on the git path paid for a partial bare clone of every branch's full history, plus clone, sparse-checkout, checkout and lazy-fetch git children, to land a cone of a few KB. For example, microsoft/apm costs 22.5 MB, 114k objects and about 2 s of git CPU.

After #4970 admission and the same transport gate the in-process pinned fetch uses (#5330/#5351), such a dependency is now two protocol-v2 requests:

  1. The pinned commit with all its trees (deepen 1, filter blob:none), only when the server advertises fetch= filter and shallow.
  2. Exactly the blobs git sparse-checkout --cone would write. The response must be exactly that set.

Every object id is computed in process. The written tree is the same as git's sparse cone. The landed .git has the in-process fetch's shape plus shallow, the trees, the cone's blobs and git's info/sparse-checkout file, and no promisor remote.

The dependency goes to git, writing nothing, when:

  • the cone holds a link, a gitlink, or an alias of .gitattributes;
  • an in-cone .gitattributes could change any written file's bytes. This is evaluated per written file by checkout_verify's attribute engine, also case-folded as core.ignorecase would match;
  • the gate refuses (same conditions as the in-process fetch; on Windows that includes the schannel backend);
  • any response or cap check fails.

The in-process sparse path is ON by default: no flag or config is needed to engage it. APM_NO_INPROCESS_SPARSE=1 is only a kill switch that forces git. It keys the install verdict record, so a recorded verdict is never reused across its values.

Merge order: #5383 lands first; this PR rebases onto it (both touch install/verdict_record.py).

Measured at 9ae2a68 against its merge-base with main, bb4744f (which already includes #5353 and #5376), on real github.com: the bench's real fixture, 10 public packages, 9 of them monorepo subdirectory or file dependencies. Cold, 6 interleaved pairs, paired CPU including children. Population: public github.com, anonymous.

OS / world base CPU p50 new CPU p50 paired new/base spawns run
Linux 6.21 s 2.45 s 0.450 78 -> 12 45513153542
macOS 6.99 s 2.83 s 0.386 86 -> 12 45513174573
Windows (default Git for Windows, schannel) 12.19 s 7.00 s 0.542 104 -> 45 45519097336

The Windows row runs the bench's real world with Git for Windows' system TLS config carried into it, as a default install has it (schannel). Before that harness fix, the isolated world hid http.sslBackend=schannel, so git ran OpenSSL with no named CA and neither main nor this PR fetched in process there (run 45513122272). A probe of the real apm install on a default runner shows the in-process hits (run 45518723251).

The control tree-50 (no subdirectory deps), cold, 6 pairs, is neutral: Linux 1.010 (45513198595), Windows 0.995 (45513232286).

Issue and approved scope

Issue: Refs #4939

Human scope-approval comment: none yet for this item. It was ordered by the PERF lead chain under #4939 (lever S). W3d ruled the conditions: w3d:ruling:lever-s S1-S12, lever-s6prime T1-T7 and lever-s-t1prime U1-U7.

This does not complete #4939.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Maintenance / refactor

Testing

  • Tested locally
  • All existing tests pass
  • Added tests for new functionality (if applicable)

Hosted-runner cells, x3 per OS:

  • tests/unit/cache + test_inprocess_fetch_world + test_inprocess_fetch_windows_world: Linux 45447526059, Windows 45447565093, macOS 45447617664. All pass except test_git_env.py::test_clone_streams_git_progress_to_reporter, a known harness-order artifact that fails in isolation on main too and passes in the full PR run.

  • test_inprocess_sparse_live passed x3 on every OS: Linux 45450785605 and macOS 45450839815 at 916c3f1, Windows 45449888782 at b7abc73 (the only later change is the engaged count, which Windows does not assert). Single-file dependencies take the file download path, not a sparse checkout.

  • tests/integration/test_inprocess_sparse_cone.py:

    • cone and info/sparse-checkout byte-equal to git's for a directory, a file and a top-level cone;
    • a CRLF blob under * text=auto eol=lf is written as git writes it;
    • eol=crlf, crlf, filter, ident, working-tree-encoding, [attr], quoted and unknown tokens refuse;
    • a pattern-aware *.bat eol=crlf with no .bat in the cone engages; a .bat or RUN.BAT in the cone refuses; a deeper override is evaluated by state;
    • an out-of-cone attributes file does not apply;
    • aliases of .gitattributes and a linked .gitattributes refuse;
    • a link in the cone refuses, and one outside the cone is ignored.
  • tests/integration/test_inprocess_sparse_attr_differential.py (W3d U6): 40 seeded trees x 2 core.ignorecase modes; every path's attribute state equals git check-attr -a.

  • tests/integration/test_inprocess_sparse_live.py (live): four real subdirectory dependencies on microsoft/apm and github/awesome-copilot, in process vs APM_NO_INPROCESS_SPARSE=1. Lockfile, deployed bytes and deploy-store receipts are identical, and every directory dependency engages on Linux and macOS.

Changelog

  • One fragment per section, changelog.d/<pr>.<section>.md, holding
    one line: user-visible effect first, 25 words or fewer, ending with
    (#PR); breaking changes only under upgrade notes; no Highlights; no
    new lines under ## [Unreleased]. See changelog.d/README.md and
    .github/instructions/changelog.instructions.md.
  • N/A -- internal-only change (CI, tests, refactor).

Spec conformance (OpenAPM v0.1)

If this PR changes behaviour that an OpenAPM v0.1 req-XXX covers,
confirm the three-step ritual in the
development guide:

  • Spec edit: docs/src/content/docs/specs/openapm-v0.1.md updated
    (new/changed <a id="req-XXX"></a> anchor + prose + Appendix C
    row).
  • Manifest edit: docs/src/content/docs/specs/manifests/openapm-v0.1.requirements.yml
    updated.
  • Test edit: a @pytest.mark.req("req-XXX") test under
    tests/spec_conformance/ added or extended.
  • CONFORMANCE.{md,json} regenerated via
    uv run --extra dev python -m tests.spec_conformance.gen_statement
    and committed.
  • N/A -- this PR does not change OpenAPM-observable behaviour.

…cone blobs, in process

A sparse (subdirectory) dependency on the git path paid a partial bare clone of
every branch's full history (microsoft/apm: 22.5 MB, 114k objects, ~2 s of git
CPU) plus clone/sparse-checkout/checkout/lazy-fetch children, for a cone of a
few KB. After #4970 admission and B1's transport gate, it is now two
protocol-v2 requests: the pinned commit with all its trees (deepen 1, filter
blob:none), then exactly the blobs `git sparse-checkout --cone` writes. Every
object id is computed in process; a response that is not exactly the wanted
set, a link, gitlink or .gitattributes alias in the cone, or an in-cone
attribute that could change bytes (evaluated per written file by
checkout_verify's engine, case-folded as core.ignorecase) sends the dependency
to git. APM_NO_INPROCESS_SPARSE=1 forces git.

W3d rulings: lever-s (S1-S12), lever-s6prime (T1-T7), lever-s-t1prime (U1-U7).
Real github.com, cold, 6 pairs: Linux 4.74 -> 2.30 s CPU (0.477), spawns 77 -> 11.

apm-spec-waiver: transport-internal fetch shape; no OpenAPM requirement changes (same lockfile, bytes and receipts as git).

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@danielmeppiel Daniel Meppiel (danielmeppiel) added the full-integration Run the full integration suite (ci-integration.yml) on this PR before merge label Nov 24, 2026
Copilot AI balanced review requested due to automatic review settings November 24, 2026 17:39
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 24, 2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved findings allow writes outside staging, produce Git-incompatible attributes and file modes, leave capability responses unbounded, and place tests where taxonomy checks reject them.

5 open issues
What changed in this PR

Extends the existing in-process pinned fetch to GitHub monorepo subdirectory dependencies, supporting the install-performance work in #4939 without replacing the Git fallback.

Changes:

  • Fetches pinned commit trees and only the blobs needed for the sparse checkout.
  • Integrates sparse landings with cache verification and attribute checks.
  • Adds Git differential tests, a live install comparison, and a performance changelog entry.
File Description
tests/​unit/​cache/​test_inprocess_sparse.py Tests cone parity, attributes, aliases, and link refusal.
tests/​unit/​cache/​test_inprocess_sparse_attr_differential.py Compares attribute evaluation with Git across seeded cases.
tests/​integration/​test_inprocess_sparse_live.py Compares live in-process and Git installs.
src/​apm_cli/​cache/​inprocess_fetch.py Adds capability discovery, sparse planning, blob fetching, and materialization.
src/​apm_cli/​cache/​git_cache.py Integrates sparse fetching and shares staging logic.
src/​apm_cli/​cache/​checkout_verify.py Adds case-insensitive attribute matching.
src/​apm_cli/​cache/​cached_repo.py Extends manifest-based link-validation skipping to sparse landings.
changelog.d/​5377.changed.md Records the reported Linux and macOS CPU improvement.

Review effort: Balanced

Comment thread src/apm_cli/cache/inprocess_fetch.py Resolved
Comment thread src/apm_cli/cache/inprocess_fetch.py Resolved
Comment thread src/apm_cli/cache/inprocess_fetch.py Resolved
Comment thread src/apm_cli/cache/inprocess_fetch.py Resolved
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 24, 2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…gated caps GET

W3d R1: every directory on the way to or inside a cone passes the same name
refusals as written files (nested .git and its aliases send the dep to git).
W3d R2: a directory that differs from the cone path only in case sends the
dep to git, as core.ignorecase cone matching would write it.
The capability GET goes through the first-answer gate and breaker, and its
per-repository memo is filled under a lock (one request per cold repository).
Attribute token names and alias folding no longer strip character sets.
The full and sparse in-process landings share one materialization-pin read.

apm-spec-waiver: transport-internal fetch shape; no OpenAPM requirement changes.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…r tests/integration (they spawn git)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
… cone, the engage-or-git verdict)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The sparse kill switch changes how install lands a dependency, so a
recorded verdict must not be reused across its values.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
….py in budget

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…th pack POSTs

The managed github-basic header is split from the env before the gate,
exactly as fetch_worktree does, and sent per request (exact origin, no
redirect hop, never on the session) on the capability GET and the trees
and blobs POSTs. Without managed auth nothing changes.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…5376)

#5376 made _requests_verify the one owner of verify= (OS store for
schannel). The caps GET now uses it, as _post does; a cell pins both to the
same value for an OS-store and a file trust.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Embedded carriage returns in .gitattributes can bypass the sparse safety gate, causing the fast path to write bytes that differ from Git and incorrectly mark the checkout as verified.

4 open issues
2 resolved since last review

Review effort: Balanced

Comment thread src/apm_cli/cache/inprocess_fetch.py Resolved
…fuse a lone CR; keep .gitattributes exec bit

- _caps_get streams the advertisement through _read_capped (shared with
  _post): identity encoding only, 64 KiB cap, 30 s wall deadline, so an
  oversized or trickling answer cannot exhaust memory or hold _caps_lock.
- An in-cone .gitattributes with a CR outside a CRLF line ending refuses:
  git splits records only on LF, so '* diff\reol=crlf' sets eol=crlf.
- A 100755 .gitattributes keeps its mode, as git writes it.
- The A' cell drives _fetch_caps through the real _admitted_post (AQ004).

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…t on (W3d R1)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

POSIX named classes and BOM-prefixed .gitattributes can cause the sparse path to write LF bytes where Git requires CRLF and incorrectly mark those files as verified.

No open issues 🎉

3 previously missed issues

In code that hasn't changed since last review

High severity Reject BOM-prefixed .gitattributes files

src/​apm_cli/​cache/​inprocess_fetch.py:1274

Git ignores a UTF-8 byte-order mark at the start of .gitattributes, but the shared parser retains it in the first pattern. A BOM followed by * eol=crlf therefore passes this gate and produces verified LF files where Git would write CRLF. Refuse BOM-prefixed sources until the canonical parser handles them, and add this case to the differential tests.

High severity Reject POSIX character classes in attribute patterns

src/​apm_cli/​cache/​inprocess_fetch.py:1282

A rule such as file[[:digit:]].md text eol=crlf passes this guard, but the shared attribute matcher does not support POSIX named classes and misses pkg/file1.md. The sparse path then writes LF bytes where Git would write CRLF and marks them verified. Conservatively refuse these patterns until the canonical matcher supports them, and add this case to the differential tests.

Medium severity Avoid holding the global lock during capability requests

src/​apm_cli/​cache/​inprocess_fetch.py:1201

The global _caps_lock is held throughout the capability GET and streamed body read, serializing capability requests across different repositories even after the first-answer gate has settled. This limits parallel downloads, and one stalled advertisement delays every other sparse dependency waiting for capabilities. Coordinate cache misses per upload URL, keeping the global lock limited to bookkeeping and preserving the existing first-answer and rate-limit gates.

4 resolved since last review

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Human assessment is needed because subtle attribute-parsing and case-matching differences from Git can cause sparse checkouts to silently write LF bytes where Git would write CRLF.

No open issues 🎉

Review effort: Balanced

@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 03bc676 into main Nov 25, 2026
67 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the perf/inprocess-sparse-fetch branch November 25, 2026 06:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

full-integration Run the full integration suite (ci-integration.yml) on this PR before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants