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

🌈 optimize(victim task):remove unused copy #2607

Closed
wants to merge 1 commit into from
Closed

🌈 optimize(victim task):remove unused copy #2607

wants to merge 1 commit into from

Conversation

kingeasternsun
Copy link
Contributor

@kingeasternsun kingeasternsun commented Dec 20, 2022

Signed-off-by: kingeasternsun kingeasternsun@gmail.com

  1. We Cloned the Task when pass it to stmt.Evict, so there is no need to convert victimTasksMap to Slice

@volcano-sh-bot volcano-sh-bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Dec 20, 2022
@kingeasternsun
Copy link
Contributor Author

/assign @shinytang6

// different filters may add the same task to victims, so use a map to remove duplicate tasks.
victimSet := make(map[*api.TaskInfo]bool)
victimSet := make(map[*api.TaskInfo]struct{})
Copy link
Member

Choose a reason for hiding this comment

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

It doesn't make much sense to do this. I read an article before, but I forgot the source. The author of the article did some tests, so it doesn't save much memory space. It also makes the code less readable.

Copy link
Contributor Author

@kingeasternsun kingeasternsun Jan 6, 2023

Choose a reason for hiding this comment

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

It doesn't make much sense to do this. I read an article before, but I forgot the source. The author of the article did some tests, so it doesn't save much memory space. It also makes the code less readable.

Actually, changing value type from bool to struct{} is not for memory save, but because the definition confused me when I first read these codes.

From the code we know that victimSet is just used to deduplicate the victim tasks, no other uses.

If we define it as map[*api.TaskInfo]struct{} ,we can determine directly from the defination that victimSet is just used for deduplication.

But if we define it as map[*api.TaskInfo]bool, which means that the value may be true or false. Function Session.VictimTasks collects victimTask by victimSet[victim] = true, which has no difference with victimSet[victim] = false, because the map value never been checked.

Copy link
Member

Choose a reason for hiding this comment

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

A boolean value can indicate the presence or absence of.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A boolean value can indicate the presence or absence of.

But in your codes , the boolean map value is never checked.
And in your codes , there is no code to set the map value to false.
vimtimSet is a map, if task in map, means presence; if not, means absence.

Copy link
Contributor

Choose a reason for hiding this comment

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

Considering this point, I agree with @hwdef that it seems to make less sense to make the value to be an empty struct object.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, Thansks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Considering this point, I agree with @hwdef that it seems to make less sense to make the value to be an empty struct object.
Has restore back to bool.

for task := range victimTasksMap {
victimTasks = append(victimTasks, task)
}
for _, victim := range victimTasks {
Copy link
Contributor

Choose a reason for hiding this comment

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

@kingeasternsun Thanks for the optimization. I approve this patch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok ,Thanks.

// different filters may add the same task to victims, so use a map to remove duplicate tasks.
victimSet := make(map[*api.TaskInfo]bool)
victimSet := make(map[*api.TaskInfo]struct{})
Copy link
Contributor

Choose a reason for hiding this comment

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

Considering this point, I agree with @hwdef that it seems to make less sense to make the value to be an empty struct object.

@volcano-sh-bot volcano-sh-bot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jan 11, 2023
Copy link
Contributor

@Thor-wl Thor-wl left a comment

Choose a reason for hiding this comment

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

@kingeasternsun It' OK for me now. Thanks for your contribution. Please rebase all the commits into one and I'll try to merge it.

Signed-off-by: kingeasternsun <kingeasternsun@gmail.com>
@volcano-sh-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To complete the pull request process, please assign shinytang6
You can assign the PR to them by writing /assign @shinytang6 in a comment when ready.

The full list of commands accepted by this bot can be found 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

@volcano-sh-bot volcano-sh-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jan 13, 2023
@kingeasternsun
Copy link
Contributor Author

@kingeasternsun It' OK for me now. Thanks for your contribution. Please rebase all the commits into one and I'll try to merge it.

Because my Incorrect operation, the commits include a merge, when I rebase -i HEAD~3, the changed files include other commits, so I pull a new PR #2652

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants