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

DeltaFIFO cleanup #70801

Merged
merged 1 commit into from
Nov 15, 2018
Merged

DeltaFIFO cleanup #70801

merged 1 commit into from
Nov 15, 2018

Conversation

Adirio
Copy link
Contributor

@Adirio Adirio commented Nov 8, 2018

What type of PR is this?
/kind cleanup
/sig api-machinery

What this PR does / why we need it:
It does a clean up of some parts of the DeltaFIFO code:

  1. A conditional that could never happen was being considered. This case checks for 0-length slices of Deltas. This slice is formed by adding a Delta to a previous slice, so it will always have at least one. After that the slice is deduped, but this method will never reduce the length to zero unless it was already zero. The behavior for zero length arrays is kept as a comment in case this can happen in the future.
    EDIT: this change has been removed from this PR as a case where this could be possible was shown by @lavalamp. Instead some cleanup has been made in the same part: the else condition is not needed as delete is a no-op for non-existing keys.
  2. A swallow copy of a slice is being done to instantly get the last element, thus making the copy useless. Issue [Question][client-go/tools/cache] DeltaFIFO.List() copy requirement #70751 tracks if a deep copy is needed, what would require a fix, but this PR keeps the current behavior.
  3. Return the closed attribute directly instead of checking it and then returning a constant.
  4. Reorder a counter decrease to stay near the element extraction

Special notes for your reviewer:
The first and last ones are mostly syntactic sugar, but the middle one should slightly improve the performance.

Does this PR introduce a user-facing change?:

NONE

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 8, 2018
@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 cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Nov 8, 2018
@k8s-ci-robot
Copy link
Contributor

Hi @Adirio. Thanks for your PR.

I'm waiting for a kubernetes 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 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 Nov 8, 2018
@Adirio
Copy link
Contributor Author

Adirio commented Nov 8, 2018

Following @k8s-ci-robot suggestion:

/assign @lavalamp

@roycaihw
Copy link
Member

roycaihw commented Nov 8, 2018

/cc

@roycaihw
Copy link
Member

/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 Nov 13, 2018
// map).
delete(f.items, id)
// newDeltas will always have at least one delta, if there is a case where
// it may have no elements, delete f.items[id] (f.queue will ignore elements
Copy link
Member

Choose a reason for hiding this comment

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

This comment is confusingly worded, as it's talking about a case that is no longer handled here without making that clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will rephrase if this change is accepted.

Copy link
Member

Choose a reason for hiding this comment

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

I recommend just removing this change and sending it in another PR; the others I can LGTM now but we're probably going to need a few iterations on the comment text here.

@lavalamp
Copy link
Member

sorry, I started reviewing this a while ago and got distracted.

I don't agree with the first change (I'm not arguing the existing code is optimal--it should at least be tested). The rest are fine.

@Adirio
Copy link
Contributor Author

Adirio commented Nov 13, 2018

I don't agree with the first change (I'm not arguing the existing code is optimal--it should at least be tested). The rest are fine.

If you still think that we should test for empty slices, I will modify this PR to only include the two last points.

Remove non-needed else condition
Remove non-needed swallow copy
Simplify return for IsClosed()
Keep amount decrement next to element extraction from the queue

Signed-off-by: Adrián Orive <adrian.orive.oneca@gmail.com>
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 14, 2018
@Adirio
Copy link
Contributor Author

Adirio commented Nov 14, 2018

@lavalamp Everything ready and checks passing (except the tide one as it requires LGTM, aproval and priority labels)

if len(newDeltas) > 0 {
if !exists {
if _, exists := f.items[id]; !exists {
Copy link
Member

Choose a reason for hiding this comment

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

I probably wouldn't have made these changes at all but I guess I don't object :)

Copy link
Member

Choose a reason for hiding this comment

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

(meaning, just these two--I'm a fan of the others)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change will mean nothing for most of the cases, as for now dedup will not yield an empty slice, but should optimize the path for empty slices. But I must agree is mostly a cosmetic change.

@lavalamp
Copy link
Member

/lgtm
/approve
/milestone v1.13

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 14, 2018
@k8s-ci-robot k8s-ci-robot added this to the v1.13 milestone Nov 14, 2018
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Adirio, lavalamp

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 Nov 14, 2018
@Adirio
Copy link
Contributor Author

Adirio commented Nov 14, 2018

I think it is just missing a priority now. Which one should I use?

@lavalamp
Copy link
Member

lavalamp commented Nov 15, 2018 via email

@k8s-ci-robot k8s-ci-robot added priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. and removed needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Nov 15, 2018
@k8s-ci-robot k8s-ci-robot merged commit 4fb368e into kubernetes:master Nov 15, 2018
@Adirio Adirio deleted the deltafifo-cleanup branch April 29, 2019 06:39
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. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. 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. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. release-note-none Denotes a PR that doesn't merit a release note. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants