You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
perf(install): skip the receipt lookup when planning an identical file - #4771
perf(install): L2 first slice of rt-06 (the no-op integrate path).
check_before_deploy runs the #4381 overwrite preflight: _planned_keeps re-runs every gated integrator (prompts, instructions, agents, commands) in planning mode, before the real run. For each file whose on-disk bytes already match the render, _check_adopt_or_skip then called receipted_unchanged. That call locates the receipt twice (_write_locator), checks the lock claim and re-hashes the file. Planning records only the files it would keep, and an identical file is never kept. Its receipt therefore cannot change the plan, and the lookup was pure cost.
The change: while planning (_overwrite_plan is not None), an identical file returns (skip=True, adopted=False) without the receipt lookup. The real run is unchanged and still reads every receipt.
Gains (GAINS STANDARD). Journey: apm install no-op, run a second time on an installed project. Fixture: tests/fixtures/perf tree-10 (seed 10), offline mirror, rtt 0. Base main 84a893b -> head 8a4f0cb (src change; later commits touch tests only). Interpreter: CPython 3.12, the same venv for both sides, sides alternated by PYTHONPATH. Every no-op left the project bytes identical, with 41 mirror requests on both sides.
run (ABAB)
side
CPU user+sys incl. children (s)
wall (s)
load1
0
main
3.503
29.7
48.9
0
head
4.921
106.1
52.2
1
main
3.393
21.3
47.4
1
head
2.895
15.5
42.8
2
main
3.014
19.0
45.4
2
head
3.203
25.8
42.7
p50
main 3.393 / head 3.203
-0.19 s CPU (1.06x, -5.6% of the whole no-op)
wall not valid (load > 30)
CPU p50 is noisy at n=3 under load 43-52; the deterministic evidence is the call counts (cProfile on the process_time clock, one run per side):
counter (tree-10 no-op)
main
head
delta
receipted_unchanged
184
94
-49%
_trusted_hash
224
134
-40%
locator_for_path
1130
860
-24%
compute_file_hash
576
486
-16%
_check_adopt_or_skip cum CPU (profiled)
1.439 s
0.869 s
-40%
check_before_deploy cum CPU (profiled)
1.996 s
1.634 s
-18%
Against the 1 s target: tree-10 no-op is at ~3.2 s CPU p50 after this slice (main 3.4 s). This slice is about 6% of the gap. The gap is dominated by integrate (skill integration, security scan, skill preflight, locators: L1) and startup/imports (L3).
tree-50: the counts scale linearly (see below), so the projected cut is ~450 receipted_unchanged calls of 917. The ABAB is PENDING (PERF host slot queue).
_planned_keeps is O(N), not O(N^2). From tree-10 to tree-50, every count scales by exactly 5x: _planned_keeps 10->50, _check_adopt_or_skip 180->900, locator_for_path 1130->5635, compute_file_hash 576->2868. The cost is one duplicate render pass of the gated primitives. Its profiled share also carries the run's first-touch costs (the discover_primitives cache misses land in planning, not in the real pass).
The planning decision is unchanged for every file. Identical files were never added to the plan before this change, and they are not now. Differing files still run the full gate (check_collision, authorizes, legacy_adoptable, _receipted_edit).
No hash is skipped or replaced by an mtime/size check. The identical verdict still comes from a full byte compare (is_content_identical_to_text / _to_source).
Planning already ran with a fresh DiagnosticCollector and discarded its counts, so adopted was never observed there.
Human scope-approval comment: PERF charter on #4732 (CEO re-charter 16:08: tree-10 no-op <= 1 s; rt-06 lane L2, integrate plan/hash).
Does this PR complete the issue, or what remains? It is the first L2 slice. Still to come: reusing planning-pass work in the real run, deduping per-run content hashes, and passing the loaded lockfile down instead of 19 deep copies.
Type of change
Bug fix
New feature
Documentation
Maintenance / refactor
Testing
Tested locally
All existing tests pass (CI; main is red on exec_gate.py LOC 1007/1000, which is not this PR)
Added tests for new functionality (if applicable)
tests/unit/integration/test_content_identical_adopt.py::TestOverwritePlanSkipsReceiptOnIdentical: planning an identical file reads no receipt and adds nothing to the plan (red before this change: the receipt is read). The real run still reads it.
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.
The #4381 overwrite preflight re-runs every gated integrator in planning
mode. Planning records only the files it would keep, and a file whose
bytes already match the render is never kept, so its deployment receipt
cannot change the plan. Skip receipted_unchanged (receipt locate, claim
check and content hash) for identical files while planning; the real
run still reads every receipt.
Refs #4732
Co-authored-by: Copilot App <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Both new tests fail on Windows because Path.write_text converts LF to CRLF, preventing the fixtures from exercising the identical-file branch; they need explicit UTF-8 bytes.
This PR reduces no-op install work by skipping receipt lookups for byte-identical files during overwrite planning, while preserving receipt checks during actual deployment.
Changes:
Return early for identical files in planning mode without marking them as adopted.
Add tests for planning-time receipt skipping and continued receipt checks during the real run.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The cited tests-only approval explicitly excludes source changes and optimizations, leaving this product optimization without a linked, applicable scope approval.
No open issues 🎉
1 previously missed issue
In code that hasn't changed since last review
Optimization lacks a matching approval scope record
src/apm_cli/integration/base_integrator.py:854
The approval record on #4732 (#4732 (comment)) is tests-only and explicitly excludes changes under src/ and optimizations, requiring separate scope records. This product optimization therefore is not covered by that record, contrary to the PR description's scope reference. Please link the newer human approval comment for the claimed rt-06/L2 re-charter, or obtain a bounded optimization scope record and update the PR description.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human confirmation of the optimization scope is needed because the fetched #4732 comments approve tests only and exclude source changes and optimizations.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
perf(install): L2 first slice of rt-06 (the no-op integrate path).
check_before_deployruns the #4381 overwrite preflight:_planned_keepsre-runs every gated integrator (prompts, instructions, agents, commands) in planning mode, before the real run. For each file whose on-disk bytes already match the render,_check_adopt_or_skipthen calledreceipted_unchanged. That call locates the receipt twice (_write_locator), checks the lock claim and re-hashes the file. Planning records only the files it would keep, and an identical file is never kept. Its receipt therefore cannot change the plan, and the lookup was pure cost.The change: while planning (
_overwrite_plan is not None), an identical file returns(skip=True, adopted=False)without the receipt lookup. The real run is unchanged and still reads every receipt.Gains (GAINS STANDARD). Journey:
apm installno-op, run a second time on an installed project. Fixture: tests/fixtures/perf tree-10 (seed 10), offline mirror, rtt 0. Base main 84a893b -> head 8a4f0cb (src change; later commits touch tests only). Interpreter: CPython 3.12, the same venv for both sides, sides alternated by PYTHONPATH. Every no-op left the project bytes identical, with 41 mirror requests on both sides.CPU p50 is noisy at n=3 under load 43-52; the deterministic evidence is the call counts (cProfile on the process_time clock, one run per side):
receipted_unchanged_trusted_hashlocator_for_pathcompute_file_hash_check_adopt_or_skipcum CPU (profiled)check_before_deploycum CPU (profiled)Against the 1 s target: tree-10 no-op is at ~3.2 s CPU p50 after this slice (main 3.4 s). This slice is about 6% of the gap. The gap is dominated by integrate (skill integration, security scan, skill preflight, locators: L1) and startup/imports (L3).
tree-50: the counts scale linearly (see below), so the projected cut is ~450
receipted_unchangedcalls of 917. The ABAB is PENDING (PERF host slot queue).Findings (main 84a893b, deterministic counts):
_planned_keepsis O(N), not O(N^2). From tree-10 to tree-50, every count scales by exactly 5x:_planned_keeps10->50,_check_adopt_or_skip180->900,locator_for_path1130->5635,compute_file_hash576->2868. The cost is one duplicate render pass of the gated primitives. Its profiled share also carries the run's first-touch costs (thediscover_primitivescache misses land in planning, not in the real pass).discover_primitivesis memoized per root (80 calls, 10 misses = 1 per package), and the lockfile YAML parse is memoized (perf(lockfile): parse each lockfile text once and load it in O(N) #4735: 1 parse, 19 deep copies).Security invariants (H8):
check_collision,authorizes,legacy_adoptable,_receipted_edit).receipted_unchanged, so receipts and adoption (RA-007, [BUG] A converged apm install still reports items as integrated and repeats warnings #4184, [BUG] Stale cleanup still trusts a lockfile hash that matches a file APM never deployed #3701) are unchanged.is_content_identical_to_text/_to_source).DiagnosticCollectorand discarded its counts, soadoptedwas never observed there.Issue and approved scope
Issue: Refs #4732
Human scope-approval comment: PERF charter on #4732 (CEO re-charter 16:08: tree-10 no-op <= 1 s; rt-06 lane L2, integrate plan/hash).
Does this PR complete the issue, or what remains? It is the first L2 slice. Still to come: reusing planning-pass work in the real run, deduping per-run content hashes, and passing the loaded lockfile down instead of 19 deep copies.
Type of change
Testing
exec_gate.pyLOC 1007/1000, which is not this PR)tests/unit/integration/test_content_identical_adopt.py::TestOverwritePlanSkipsReceiptOnIdentical: planning an identical file reads no receipt and adds nothing to the plan (red before this change: the receipt is read). The real run still reads it.Changelog
changelog.d/<pr>.<section>.md, holdingone line: user-visible effect first, 25 words or fewer, ending with
(#PR); breaking changes only under upgrade notes; no Highlights; nonew lines under
## [Unreleased]. Seechangelog.d/README.mdand.github/instructions/changelog.instructions.md.Spec conformance (OpenAPM v0.1)
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.