Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚠️ Change client.Patch to take client.Object for performance #1395

Merged
merged 2 commits into from
Mar 3, 2021

Conversation

cbandy
Copy link
Contributor

@cbandy cbandy commented Feb 24, 2021

Most uses of merge-patch will be for built-in types or kubebuilder-generated custom resources which have accessors for ResourceVersion. Using these with DeepCopyObject() is simple and fast.

name                            old time/op    new time/op    delta
MergeFrom/NoOptions               91.6µs ± 4%   107.3µs ±26%     ~     (p=0.417 n=7+10)
MergeFrom/NoOptions-2              112µs ±18%      88µs ±11%  -21.15%  (p=0.000 n=10+9)
MergeFrom/WithOptimisticLock       163µs ± 3%     121µs ± 3%  -25.66%  (p=0.000 n=10+8)
MergeFrom/WithOptimisticLock-2     137µs ± 4%     101µs ± 4%  -26.28%  (p=0.000 n=10+10)

name                            old alloc/op   new alloc/op   delta
MergeFrom/NoOptions               20.3kB ± 0%    20.3kB ± 0%     ~     (all equal)
MergeFrom/NoOptions-2             20.3kB ± 0%    20.3kB ± 0%     ~     (all equal)
MergeFrom/WithOptimisticLock      34.1kB ± 0%    26.7kB ± 0%  -21.89%  (p=0.000 n=10+10)
MergeFrom/WithOptimisticLock-2    34.2kB ± 0%    26.7kB ± 0%  -21.89%  (p=0.000 n=10+8)

name                            old allocs/op  new allocs/op  delta
MergeFrom/NoOptions                  359 ± 0%       359 ± 0%     ~     (all equal)
MergeFrom/NoOptions-2                359 ± 0%       359 ± 0%     ~     (all equal)
MergeFrom/WithOptimisticLock         579 ± 0%       390 ± 0%  -32.64%  (p=0.000 n=10+10)
MergeFrom/WithOptimisticLock-2       579 ± 0%       390 ± 0%  -32.64%  (p=0.000 n=10+10)

@k8s-ci-robot
Copy link
Contributor

Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA.

It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.


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. I understand the commands that are listed here.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Feb 24, 2021
@k8s-ci-robot
Copy link
Contributor

Welcome @cbandy!

It looks like this is your first PR to kubernetes-sigs/controller-runtime 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/controller-runtime has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot
Copy link
Contributor

Hi @cbandy. 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.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Feb 24, 2021
@cbandy
Copy link
Contributor Author

cbandy commented Feb 24, 2021

I signed it

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Feb 24, 2021
pkg/client/patch.go Outdated Show resolved Hide resolved
@vincepri
Copy link
Member

vincepri commented Mar 1, 2021

/milestone v0.9.x

If we switch the interface accepted in the method, we need to mark this as ⚠️

@k8s-ci-robot k8s-ci-robot added this to the v0.9.x milestone Mar 1, 2021
@vincepri
Copy link
Member

vincepri commented Mar 1, 2021

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Mar 1, 2021
@cbandy
Copy link
Contributor Author

cbandy commented Mar 2, 2021

If we're changing the signatures, perhaps we should add an options vararg to MergeFrom like other patch constructors the Client methods.

@vincepri
Copy link
Member

vincepri commented Mar 2, 2021

@cbandy Could we discuss that change in a separate issue?

@cbandy
Copy link
Contributor Author

cbandy commented Mar 2, 2021

@cbandy Could we discuss that change in a separate issue?

Certainly. Is the signature (with runtime.Object) acceptable as-is in this PR?

@vincepri
Copy link
Member

vincepri commented Mar 2, 2021

We should move to client.Object and always use the fast path, there is no need to use the old runtime.Object

Most uses of merge-patch will be for built-in types or kubebuilder-
generated custom resources which have accessors for ResourceVersion.
Using these with DeepCopyObject() is simple and fast.

name                            old time/op    new time/op    delta
MergeFrom/NoOptions               91.6µs ± 4%   107.3µs ±26%     ~     (p=0.417 n=7+10)
MergeFrom/NoOptions-2              112µs ±18%      88µs ±11%  -21.15%  (p=0.000 n=10+9)
MergeFrom/WithOptimisticLock       163µs ± 3%     121µs ± 3%  -25.66%  (p=0.000 n=10+8)
MergeFrom/WithOptimisticLock-2     137µs ± 4%     101µs ± 4%  -26.28%  (p=0.000 n=10+10)

name                            old alloc/op   new alloc/op   delta
MergeFrom/NoOptions               20.3kB ± 0%    20.3kB ± 0%     ~     (all equal)
MergeFrom/NoOptions-2             20.3kB ± 0%    20.3kB ± 0%     ~     (all equal)
MergeFrom/WithOptimisticLock      34.1kB ± 0%    26.7kB ± 0%  -21.89%  (p=0.000 n=10+10)
MergeFrom/WithOptimisticLock-2    34.2kB ± 0%    26.7kB ± 0%  -21.89%  (p=0.000 n=10+8)

name                            old allocs/op  new allocs/op  delta
MergeFrom/NoOptions                  359 ± 0%       359 ± 0%     ~     (all equal)
MergeFrom/NoOptions-2                359 ± 0%       359 ± 0%     ~     (all equal)
MergeFrom/WithOptimisticLock         579 ± 0%       390 ± 0%  -32.64%  (p=0.000 n=10+10)
MergeFrom/WithOptimisticLock-2       579 ± 0%       390 ± 0%  -32.64%  (p=0.000 n=10+10)
This allows us to use metav1 accessors to speed up the merge-patch
implementation.
@cbandy cbandy changed the title ✨ Add a fast path for client.Object in merge-patch ⚠️ Change client.Patch to take client.Object for performance Mar 3, 2021
@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented Mar 3, 2021

@cbandy: The following test failed, say /retest to rerun all failed tests:

Test name Commit Details Rerun command
pull-controller-runtime-apidiff-master aef159a link /test pull-controller-runtime-apidiff-master

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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. I understand the commands that are listed here.

@vincepri
Copy link
Member

vincepri commented Mar 3, 2021

LGTM please squash commits

@vincepri
Copy link
Member

vincepri commented Mar 3, 2021

/milestone v0.9.x

@vincepri
Copy link
Member

vincepri commented Mar 3, 2021

/assign @alvaroaleman

Copy link
Member

@alvaroaleman alvaroaleman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/label tide/merge-method-squash
/lgtm

@k8s-ci-robot k8s-ci-robot added tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. lgtm "Looks good to me", indicates that a PR is ready to be merged. labels Mar 3, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alvaroaleman, cbandy

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 3, 2021
@k8s-ci-robot k8s-ci-robot merged commit a79f6f1 into kubernetes-sigs:master Mar 3, 2021
@cbandy cbandy deleted the optimistic-merge branch March 3, 2021 19:55
timebertt added a commit to gardener/gardener that referenced this pull request Jun 16, 2021
* Upgrade to k/*@v0.21.1 in go.mod

* [automated] make revendor for k/* dependencies

This deletes pkg/mock/client-go/kubernetes/mocks.go to resolve the
following deadlock: make revendor fails because of some dependencies
of the file and make generate fails because of missing revendoring.
File will be generated again in the next commit.

* [automated] make generate for k/* dependencies

* Upgrade to c-r@v0.9.0 in go.mod

* [automated] make revendor for c-r dependency

`make revendor` results in `hack/setup-envtest.sh` being broken, so reset
the file after running `make revendor`. Adaption to breaking changes
in the upstream file will be done in a later commit.

* manager.NewClientBuilder was removed in favor of cluster.DefaultNewClient

ref kubernetes-sigs/controller-runtime#1409

* client.*MergeFrom* now take client.Object instead of runtime.Object

ref kubernetes-sigs/controller-runtime#1395

* [automated] make generate for c-r dependency

* Adapt to changes in labels.NewRequirement

ref kubernetes/kubernetes#97538

* Adapt to new setup-envtest tool

Makes use of the new setup-envtest tool (kubernetes-sigs/controller-runtime#1488)
in hack/setup-envtest.sh instead of vendoring hack/setup-envtest.sh and fetching
binaries with that.

* [automated] make revendor for setup-envtest tool

* Adapt pkg/envtest to upstream changes

- Make use of the new Users concept in envtest to provision a dedicated
  user for gardener-apiserver and a valid kubeconfig

- Make use of the new way to configure API server args to easily configure
  kube-aggregator flags

- Also generate certs for aggregation layer on our own instead of reusing
  the API server ca/certs (which is semantically correct), which allows us
  to drop our fork including kubernetes-sigs/controller-runtime#1449

* Styling nits
RainbowMango pushed a commit to RainbowMango/controller-runtime that referenced this pull request Sep 1, 2021
…tes-sigs#1395)

* ✨ Add a fast path for client.Object in merge-patch

Most uses of merge-patch will be for built-in types or kubebuilder-
generated custom resources which have accessors for ResourceVersion.
Using these with DeepCopyObject() is simple and fast.

name                            old time/op    new time/op    delta
MergeFrom/NoOptions               91.6µs ± 4%   107.3µs ±26%     ~     (p=0.417 n=7+10)
MergeFrom/NoOptions-2              112µs ±18%      88µs ±11%  -21.15%  (p=0.000 n=10+9)
MergeFrom/WithOptimisticLock       163µs ± 3%     121µs ± 3%  -25.66%  (p=0.000 n=10+8)
MergeFrom/WithOptimisticLock-2     137µs ± 4%     101µs ± 4%  -26.28%  (p=0.000 n=10+10)

name                            old alloc/op   new alloc/op   delta
MergeFrom/NoOptions               20.3kB ± 0%    20.3kB ± 0%     ~     (all equal)
MergeFrom/NoOptions-2             20.3kB ± 0%    20.3kB ± 0%     ~     (all equal)
MergeFrom/WithOptimisticLock      34.1kB ± 0%    26.7kB ± 0%  -21.89%  (p=0.000 n=10+10)
MergeFrom/WithOptimisticLock-2    34.2kB ± 0%    26.7kB ± 0%  -21.89%  (p=0.000 n=10+8)

name                            old allocs/op  new allocs/op  delta
MergeFrom/NoOptions                  359 ± 0%       359 ± 0%     ~     (all equal)
MergeFrom/NoOptions-2                359 ± 0%       359 ± 0%     ~     (all equal)
MergeFrom/WithOptimisticLock         579 ± 0%       390 ± 0%  -32.64%  (p=0.000 n=10+10)
MergeFrom/WithOptimisticLock-2       579 ± 0%       390 ± 0%  -32.64%  (p=0.000 n=10+10)

* ⚠ Change client.Patch to take client.Object

This allows us to use metav1 accessors to speed up the merge-patch
implementation.
krgostev pushed a commit to krgostev/gardener that referenced this pull request Apr 21, 2022
* Upgrade to k/*@v0.21.1 in go.mod

* [automated] make revendor for k/* dependencies

This deletes pkg/mock/client-go/kubernetes/mocks.go to resolve the
following deadlock: make revendor fails because of some dependencies
of the file and make generate fails because of missing revendoring.
File will be generated again in the next commit.

* [automated] make generate for k/* dependencies

* Upgrade to c-r@v0.9.0 in go.mod

* [automated] make revendor for c-r dependency

`make revendor` results in `hack/setup-envtest.sh` being broken, so reset
the file after running `make revendor`. Adaption to breaking changes
in the upstream file will be done in a later commit.

* manager.NewClientBuilder was removed in favor of cluster.DefaultNewClient

ref kubernetes-sigs/controller-runtime#1409

* client.*MergeFrom* now take client.Object instead of runtime.Object

ref kubernetes-sigs/controller-runtime#1395

* [automated] make generate for c-r dependency

* Adapt to changes in labels.NewRequirement

ref kubernetes/kubernetes#97538

* Adapt to new setup-envtest tool

Makes use of the new setup-envtest tool (kubernetes-sigs/controller-runtime#1488)
in hack/setup-envtest.sh instead of vendoring hack/setup-envtest.sh and fetching
binaries with that.

* [automated] make revendor for setup-envtest tool

* Adapt pkg/envtest to upstream changes

- Make use of the new Users concept in envtest to provision a dedicated
  user for gardener-apiserver and a valid kubeconfig

- Make use of the new way to configure API server args to easily configure
  kube-aggregator flags

- Also generate certs for aggregation layer on our own instead of reusing
  the API server ca/certs (which is semantically correct), which allows us
  to drop our fork including kubernetes-sigs/controller-runtime#1449

* Styling nits
krgostev pushed a commit to krgostev/gardener that referenced this pull request Jul 5, 2022
* Upgrade to k/*@v0.21.1 in go.mod

* [automated] make revendor for k/* dependencies

This deletes pkg/mock/client-go/kubernetes/mocks.go to resolve the
following deadlock: make revendor fails because of some dependencies
of the file and make generate fails because of missing revendoring.
File will be generated again in the next commit.

* [automated] make generate for k/* dependencies

* Upgrade to c-r@v0.9.0 in go.mod

* [automated] make revendor for c-r dependency

`make revendor` results in `hack/setup-envtest.sh` being broken, so reset
the file after running `make revendor`. Adaption to breaking changes
in the upstream file will be done in a later commit.

* manager.NewClientBuilder was removed in favor of cluster.DefaultNewClient

ref kubernetes-sigs/controller-runtime#1409

* client.*MergeFrom* now take client.Object instead of runtime.Object

ref kubernetes-sigs/controller-runtime#1395

* [automated] make generate for c-r dependency

* Adapt to changes in labels.NewRequirement

ref kubernetes/kubernetes#97538

* Adapt to new setup-envtest tool

Makes use of the new setup-envtest tool (kubernetes-sigs/controller-runtime#1488)
in hack/setup-envtest.sh instead of vendoring hack/setup-envtest.sh and fetching
binaries with that.

* [automated] make revendor for setup-envtest tool

* Adapt pkg/envtest to upstream changes

- Make use of the new Users concept in envtest to provision a dedicated
  user for gardener-apiserver and a valid kubeconfig

- Make use of the new way to configure API server args to easily configure
  kube-aggregator flags

- Also generate certs for aggregation layer on our own instead of reusing
  the API server ca/certs (which is semantically correct), which allows us
  to drop our fork including kubernetes-sigs/controller-runtime#1449

* Styling nits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants