perf: cache Resource.CurId & PrevIds return value
Cache the return value for both Resource.CurId and Resource.PrevIds to improve overall performance. These changes have minor effects on small kustomize runs, but can provide significant benefits for larger runs.
Edited to add: This work significantly helps https://github.com/kubernetes-sigs/kustomize/issues/5084#issuecomment-1806477953.
Hi @ephesused. Thanks for your PR.
I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.
Once the patch is verified, the new status will be reflected by the ok-to-test label.
I understand the commands that are listed here.
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
[APPROVALNOTIFIER] This PR is NOT APPROVED
This pull-request has been approved by: ephesused Once this PR has been reviewed and has the lgtm label, please assign koba1t for approval. For more information see the Kubernetes Code Review Process.
The full list of commands accepted by this bot can be found here.
Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment
Highlighting a few comments from what I wrote over in https://github.com/kubernetes-sigs/kustomize/issues/5084#issuecomment-1806477953:
... do you know if there are reasons why caching Resource.CurId() could be problematic? I feel like there may be hidden pitfalls here. Is this sort of caching in line with kustomize coding patterns? In addition to resWrangler.appendReplaceOrMerge, are there other spots that might adjust a resource in a way that could alter its ResId, but do not issue a call to Resource.setPreviousId()? Anything other aspect I might be missing?
Test results from my runs show meaningful improvements where I expected, with identical kustomize output between the PR and v5.3.0.
A testcase based on #2869:
kustomize_test.go:289: Runtime variation (0.56x): branch-pr-5481 ran in 433ms; release-v5.3.0 ran in 769ms.
Moderately sized content with somewhat complex kustomizations:
kustomize_test.go:289: Runtime variation (0.85x): branch-pr-5481 ran in 16043ms; release-v5.3.0 ran in 18772ms.
Large content with complex kustomizations:
kustomize_test.go:289: Runtime variation (0.72x): branch-pr-5481 ran in 144304ms; release-v5.3.0 ran in 200504ms.
The Kubernetes project currently lacks enough contributors to adequately respond to all PRs.
This bot triages PRs according to the following rules:
- After 90d of inactivity,
lifecycle/staleis applied - After 30d of inactivity since
lifecycle/stalewas applied,lifecycle/rottenis applied - After 30d of inactivity since
lifecycle/rottenwas applied, the PR is closed
You can:
- Mark this PR as fresh with
/remove-lifecycle stale - Close this PR with
/close - Offer to help out with Issue Triage
Please send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle stale
The Kubernetes project currently lacks enough active contributors to adequately respond to all PRs.
This bot triages PRs according to the following rules:
- After 90d of inactivity,
lifecycle/staleis applied - After 30d of inactivity since
lifecycle/stalewas applied,lifecycle/rottenis applied - After 30d of inactivity since
lifecycle/rottenwas applied, the PR is closed
You can:
- Mark this PR as fresh with
/remove-lifecycle rotten - Close this PR with
/close - Offer to help out with Issue Triage
Please send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle rotten
I'd like this to be considered.
/remove-lifecycle rotten