Repository navigation
perf(install): no per-dependency git process on warm-cache installs - #4836
Daniel Meppiel (danielmeppiel) wants to merge 6 commits into
Conversation
…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]>
Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🟡 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
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]>
|
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. |
There was a problem hiding this comment.
🟡 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") |
| if not ( | ||
| checkout_dir.is_dir() | ||
| and verify_checkout_sha(checkout_dir, sha) | ||
| and _checkout_has_materialization_pins(checkout_dir) | ||
| ): |


Description
Warm-cache installs (no-op, lockfile-locked,
--frozenwith a warm cache) still start onegit ls-treeper dependency, plus 8-18git remotereads and a TLSgit configprobe 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.git_cachematerializes a full shard and finds no unresolvable link, thegit_sparseowner writes.git/apm-links-cleancontaining 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.GitCache.pinned_checkout. For a lockfile-pinned SHA, a verified full-shard hit (HEAD + materialization pins, same checks asget_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.git remoteread once per command. This folds perf(policy): read the project git remote once per command run #4778 (L5, credited): a memo overcore/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):--frozen, warm cache)tree-50: per-dependency
ls-tree50 -> 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):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
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_checkouthit 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.py109 passed; lint mirror (ruff check/format at the pinned version, auth-signal lint, complexity ratchet, taxonomy, AQ ratchet) clean.Changelog
changelog.d/<pr>.<section>.md.Spec conformance (OpenAPM v0.1)
If this PR changes behaviour that an OpenAPM v0.1
req-XXXcovers,confirm the three-step ritual in the
development guide:
docs/src/content/docs/specs/openapm-v0.1.mdupdated(new/changed
<a id="req-XXX"></a>anchor + prose + Appendix Crow).
docs/src/content/docs/specs/manifests/openapm-v0.1.requirements.ymlupdated.
@pytest.mark.req("req-XXX")test undertests/spec_conformance/added or extended.CONFORMANCE.{md,json}regenerated viauv run --extra dev python -m tests.spec_conformance.gen_statementand committed.
apm-spec-waiverin the commit message).