Skip to content

perf(install): no per-dependency git process on warm-cache installs - #4836

Closed
Daniel Meppiel (danielmeppiel) wants to merge 6 commits into
mainfrom
danielmeppiel-perf-zero-spawn-warm
Closed

Daniel Meppiel (danielmeppiel) wants to merge 6 commits into
mainfrom
danielmeppiel-perf-zero-spawn-warm

Conversation

@danielmeppiel

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

Copy link
Copy Markdown
Collaborator

Description

Warm-cache installs (no-op, lockfile-locked, --frozen with a warm cache) still start one git ls-tree per dependency, plus 8-18 git remote reads and a TLS git config probe per command, even when every pinned commit is already in the cache. This PR removes the per-dependency process and memoizes the per-command reads, with no change to any integrity, auth or policy decision.

  1. Links-clean record (O(N) -> O(1)). When git_cache materializes a full shard and finds no unresolvable link, the git_sparse owner writes .git/apm-links-clean containing the shard's commit SHA. On a cache hit, validate_materialized_symlinks(..., clean_for=<sha>) trusts that record instead of listing the tree again. Unresolvable links never get a record, so they still raise. A different commit or a scoped check lists the tree as before. The record has the same trust as the shard's HEAD and pins, which the hit already relies on.
  2. GitCache.pinned_checkout. For a lockfile-pinned SHA, a verified full-shard hit (HEAD + materialization pins, same checks as get_checkout, recency refreshed) is returned before the auth fallback builds a git environment. A hit therefore runs no git process at all. Sparse variants, refresh, read-only caches and any unverified shard take the old path unchanged.
  3. Policy git remote read once per command. This folds perf(policy): read the project git remote once per command run #4778 (L5, credited): a memo over core/invocation_memo, the same per-command scope as the fix(policy): fetch an org's absent policy once per command run #4786 policy-404 memo. Lifecycle scripts still drop it.

Issue and approved scope

Issue: Fixes #4841. Supersedes #4778.

Human scope-approval comment: the accepted scope record on #4841 (status/accepted).

Does this PR complete the issue, or what remains? It completes the per-dependency floor. What remains is per command and is a correctness floor: one memoized policy remote read (git applies insteadOf and includes, so it is not hand-parsed), and on lockfile-less installs one tag resolution per dependency (tags move).

GAINS (counts are deterministic; CPU from the CI bench)

tree-10 offline mirror, base main f0dab6c2 -> head (PATH-shim spawn counter + offline proxy):

Journey Spawns before -> after Requests before -> after
no-op install 8 -> 2 0 -> 0
warm, lockfile (--frozen, warm cache) 29 -> 2 0 -> 0
warm, no lockfile 23 -> 3 10 -> 10 (1 tag resolution per dep)

tree-50: per-dependency ls-tree 50 -> 0 (it scaled O(N)); frozen-warm 73 -> 2 spawns.

CI bench run 45078453704 (base f0dab6c2 -> c87505d3, tree-10, rtt 30, 3 runners x 3 interleaved pairs, CPU user+sys incl. children):

Journey CPU p50 base -> new Paired new/base Spawns Requests
install-frozen-warm 2.512 -> 2.475 s 0.991 29 -> 2 0 -> 0
install-locked-warm 2.233 -> 2.210 s 0.989 23 -> 2 0 -> 0
install-noop 2.046 -> 2.031 s 0.993 8 -> 2 0 -> 0
install-warm 2.424 -> 2.400 s 0.998 23 -> 3 10 -> 10

Honest read: on Linux runners a git spawn costs a few ms, so CPU moves about 1%. The value is the locked floor (a guard against per-dependency process regressions) and the O(N) removal, which matters more where process creation is expensive (Windows) and at larger N.

Type of change

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

Testing

  • Tested locally

  • All existing tests pass

  • Added tests for new functionality (if applicable)

  • tests/integration/test_warm_install_spawn_budget.py (new floor guard, e2e): red at main (8 / 29 / 23 spawns), green here.

  • tests/unit/cache/test_git_cache_symlinks.py: links-clean record trusted only for its commit and only for whole-tree checks; never written for a shard with an unresolvable link; pinned_checkout hit runs no git, refreshes recency, and refuses sparse, refresh, non-SHA, missing and unverified shards.

  • tests/unit/policy/test_remote_memo.py (from perf(policy): read the project git remote once per command run #4778).

  • Local: guard + tests/unit/policy/test_discovery.py 109 passed; lint mirror (ruff check/format at the pinned version, auth-signal lint, complexity ratchet, taxonomy, AQ ratchet) clean.

Changelog

  • One fragment per section, changelog.d/<pr>.<section>.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 (apm-spec-waiver in the commit message).

…uard)

A PATH shim counts every git/gh process the CLI starts and the offline
proxy counts requests on the tree-10 mirror: a no-op install and a frozen
replay from a warm cache must spawn nothing and request nothing; a warm
install without a lockfile spawns nothing and resolves each ref once.
Red at main f0dab6c: 8 / 29 / 23 spawns.

Co-authored-by: Copilot App <[email protected]>
- git_sparse: a full shard materialized with no unresolvable link records
  a links-clean marker bound to its commit; a cache-hit validation of that
  commit trusts it instead of running `git ls-tree` per dependency (O(N)).
- GitCache.pinned_checkout: a verified hit for a lockfile-pinned SHA is
  returned before the auth fallback builds a git env, so a hit runs no git.
- policy/_remote: one `git remote` read per command (memo over
  core/invocation_memo; ported from #4778).

tree-10 counts (main f0dab6c -> this): no-op 8 -> 2 spawns, frozen 29 -> 2,
warm 23 -> 3; tree-50 per-dependency ls-tree 50 -> 0.

apm-spec-waiver: cache-hit and policy remote-read process counts only; no OpenAPM-observable behaviour change

Co-authored-by: L5 PERF engineer 6ffa7618 (policy remote memo, #4778)
Co-authored-by: Copilot App <[email protected]>
…l memo

The new component tests assert the recorded marker and the untouched
unverified shard (AQ003). policy/_remote.py and its test now match #4778
at fe1bf3b (equivalent relative and absolute roots share one read).

Co-authored-by: L5 PERF engineer 6ffa7618 (policy remote memo, #4778)
Co-authored-by: Copilot App <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 22, 2026 22:32
Co-authored-by: Copilot App <[email protected]>

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

Existing warm shards never acquire the apm-links-clean marker after successful fallback validation, causing repeated per-dependency git ls-tree calls on every replay; writable-shard backfilling and regression coverage are needed.

1 open issue
What changed in this PR

This PR reduces Git subprocess overhead in warm-cache installs by reusing verified checkout state and memoizing policy remote reads within each command.

Changes:

  • Records successful whole-tree symlink materialization so matching cache hits can skip tree scans.
  • Adds a pinned-checkout fast path before authentication environment setup.
  • Memoizes policy remote reads and adds unit and end-to-end regression coverage.
File Description
tests/​unit/​policy/​test_remote_memo.py Tests per-command remote caching, key isolation, and failure reuse.
tests/​unit/​cache/​test_git_cache_symlinks.py Tests clean markers and verified, subprocess-free pinned hits.
tests/​integration/​test_warm_install_spawn_budget.py Checks subprocess and request budgets across warm-install journeys.
src/​apm_cli/​utils/​git_sparse.py Writes and consults commit-specific symlink-clean records.
src/​apm_cli/​policy/​_remote.py Memoizes Git remote reads within an invocation.
src/​apm_cli/​deps/​github_downloader.py Uses pinned cache hits and clean-record validation.
src/​apm_cli/​cache/​git_cache.py Adds pinned-checkout lookup and records clean materialization.
changelog.d/​4836.changed.md Describes the warm-install performance improvement.

Review effort: Balanced

Comment thread src/apm_cli/utils/git_sparse.py Resolved
Shards from before the record kept paying one `git ls-tree` per dependency
on every warm hit. A writable full-shard hit (get_checkout or
pinned_checkout) now records it once via git_sparse.record_links_clean when
the whole tree has no unresolvable link; read-only caches never write. The
test counting re-listings now asserts each case instead of a total.

Co-authored-by: Copilot App <[email protected]>
@danielmeppiel

Copy link
Copy Markdown
Collaborator Author

Closed by [PERF] VP v2 under the PERF landing bar (a CI-bench paired-CPU run at head showing >= 2x or >= 30% on the target journey). Run 45078453704 (base f0dab6c -> c87505d, tree-10, rtt 30, 3 runners x 3 pairs): spawns drop hard (frozen-warm 29 -> 2, locked-warm 23 -> 2, no-op 8 -> 2, warm 23 -> 3), but paired CPU barely moves (0.991 / 0.989 / 0.993 / 0.998): a git spawn costs a few ms on Linux. The possible Windows win (process creation ~30-50 ms) and the O(N) per-dep ls-tree at tree-200 are unmeasured; they stay research on branch danielmeppiel-perf-zero-spawn-warm until a Windows or tree-200 bench shows the bar.

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

An active critical issue allows symlinked marker writes to truncate files outside the cache, while duplicated cache-hit verification logic risks integrity checks drifting between entry points.

2 open issues
1 resolved since last review

Review effort: Balanced

)
if failures:
return False
marker.write_text(sha.strip().lower() + "\n", encoding="ascii")
Comment on lines +455 to +459
if not (
checkout_dir.is_dir()
and verify_checkout_sha(checkout_dir, sha)
and _checkout_has_materialization_pins(checkout_dir)
):
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.

[FEATURE] perf(install): no per-dependency git process on warm-cache installs

2 participants