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

Avoid unnecessary calls to Container.Config() and Container.Spec() #16123

Merged
merged 4 commits into from
Oct 12, 2022

Conversation

alexlarsson
Copy link
Contributor

As mentioned in #16117 there are more places in the codebase where we unnecessarily call these expensive functions. This removes a bunch of them by calling existing or new accessors, or in some cases by using .ConfigNoCopy() instead.

@vrothberg

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Oct 12, 2022

@alexlarsson: Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

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.

@openshift-ci openshift-ci bot added the do-not-merge/release-note-label-needed Enforce release-note requirement, even if just None label Oct 12, 2022
@github-actions github-actions bot added the kind/api-change Change to remote API; merits scrutiny label Oct 12, 2022
libpod/container.go Outdated Show resolved Hide resolved
@@ -688,6 +688,14 @@ func (c *Container) Terminal() bool {
return false
}

// LinuxResources return the contaienrs Linux Resources (if any)
func (c *Container) LinuxResources() *spec.LinuxResources {
Copy link
Member

Choose a reason for hiding this comment

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

Does this change really have positive performance impacts? I'd expect the compiler to be smart enough to allocate a variable but did not decompile.

What callers now have is one additional nil check (i.e., if resources != nil), so my gut feeling is performance suffered.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Most of the callers were indeed not affected, and some may have actually been made a few cycles slower. However, the call in moveConmonToCgroupAndSignal() now avoids a call to container.Spec() which saves around 2 milliseconds (bazillions of cycles), so it does affect performance.

Now, one could add a hack just for that particular caller, but imho most of the callers that were changed to use the helper are shorter, easier to read, and generally more maintainable, while suffering negligible performance decrease.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(8 million cycles on my machine)

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for elaborating on that. The argument seems convincing to me. @mheon WDYT?

@rhatdan
Copy link
Member

rhatdan commented Oct 12, 2022

LGTM
@mheon PTAL

This gets c.config.Spec.Linux.Resources, with some nil checks.
Using this means less open coding of the nil-checks, but also the
existing user of this field in moveConmonToCgroupAndSignal() was
using ctr.Spec().Linux.Resources instead, and the Spec() call
is very expensive.

[NO NEW TESTS NEEDED] Just minor performance effects

Signed-off-by: Alexander Larsson <[email protected]>
This call does a deep copy, which is only needed if you want
to modify the return value. Instead we use ctr.ConfigNoCopy().Spec
which is just a pointer dereference.

[NO NEW TESTS NEEDED] Just minor performance effects

Signed-off-by: Alexander Larsson <[email protected]>
This is a very expensive function as it does a deep copy. Instead
use pre-existing accessors like ctr.CreatedTime() where they exist
and ctr.ConfigNoCopy() where not.

[NO NEW TESTS NEEDED] Just minor performance effects

Signed-off-by: Alexander Larsson <[email protected]>
This is a very expensive call as it deep duplicates the Config, and
we just need to read a single member, so use ConfigNoCopy() instead.

[NO NEW TESTS NEEDED] Just minor performance effects

Signed-off-by: Alexander Larsson <[email protected]>
@rhatdan rhatdan removed the do-not-merge/release-note-label-needed Enforce release-note requirement, even if just None label Oct 12, 2022
@mheon
Copy link
Member

mheon commented Oct 12, 2022

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Oct 12, 2022
@rhatdan
Copy link
Member

rhatdan commented Oct 12, 2022

/approve

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Oct 12, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alexlarsson, rhatdan

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

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 12, 2022
@rhatdan rhatdan merged commit b13939b into containers:main Oct 12, 2022
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 20, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/api-change Change to remote API; merits scrutiny lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants