refactor(toolkit-lib): drop the deep clone used to remove one metadata key - #1826
Open
Adityaj0 wants to merge 1 commit into
Open
refactor(toolkit-lib): drop the deep clone used to remove one metadata key#1826Adityaj0 wants to merge 1 commit into
Adityaj0 wants to merge 1 commit into
Conversation
Adityaj0
requested a deployment
to
integ-approval
August 12, 2026 08:33 — with
GitHub Actions
Waiting
aws-cdk-automation
enabled auto-merge
August 12, 2026 08:33
…a key `stripConstructPath` removes `Metadata['aws:cdk:path']` before hashing a resource, and does it by round-tripping the whole resource through `JSON.parse(JSON.stringify(...))`. Every CDK-generated resource carries that key, so a refactor pays a full serialize + parse of every resource in every stack, on both sides of the comparison, in both graph directions. The clone is unnecessary: the caller only reads the result, and the single key being removed sits one level down. A shallow copy of the resource and of its `Metadata` is enough, and keeps the caller's template unmodified. Measured on synthetic CDK-shaped templates (cold process, min of 7): 20-25% off the digest phase of a refactor, depending on template size. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
auto-merge was automatically disabled
August 12, 2026 08:36
Head branch was pushed to by a user without write access
Adityaj0
force-pushed
the
perf/refactor-digest-no-deep-clone
branch
from
August 12, 2026 08:36
534201d to
4c23950
Compare
Adityaj0
requested a deployment
to
integ-approval
August 12, 2026 08:36 — with
GitHub Actions
Waiting
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #1823
Reason for this change
stripConstructPathremovesMetadata['aws:cdk:path']before a resource is hashed, and does it by round-tripping the whole resource throughJSON.parse(JSON.stringify(...)). The cost scales with the size of the resource rather than with the one key being removed, and every CDK-generated resource carries that key — including the large ones (inline policy documents, state machine definitions, inline Lambda code).The clone is not needed for correctness. The result is only read: it goes straight into
stripReferences, which builds its own new tree. And aRefactoringContextrunscomputeResourceDigestsfour times per environment (deployed and local stacks, in both graph directions), so each resource is cloned four times per refactor.Description of changes
Shallow-copy the resource and its
Metadatamap instead:Same output, same guarantee that the caller's template is left untouched, and the cost no longer depends on how big the resource is.
Description of how you validated changes
Digests are byte-identical before and after: asserted the full digest map for both graph directions against the current implementation's output on CDK-shaped templates.
New regression test covering the properties this relies on: metadata other than the construct path still contributes to the digest, the caller's
Metadataobject is not modified, and repeated calls are stable.All 55 tests under
test/api/refactoring/pass.Benchmark — synthetic CDK-shaped templates (nested policy documents, tags,
Ref/Fn::GetAttcross-references,DependsOn,aws:cdk:pathon every resource), timing the fourcomputeResourceDigestscalls oneRefactoringContextperforms. Cold node process per measurement, min of 7 runs:Note: #1824 covers a second, larger inefficiency in the same four passes (each resource's property hash is recomputed once per graph direction). The two changes are independent and compose; this one is the smaller, self-contained half.
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license