-
Notifications
You must be signed in to change notification settings - Fork 946
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
🌈 optimize(victim task):remove unused copy #2607
Conversation
/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{}) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, Thansks
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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{}) |
There was a problem hiding this comment.
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.
There was a problem hiding this 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>
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 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 |
Because my Incorrect operation, the commits include a merge, when I |
Signed-off-by: kingeasternsun kingeasternsun@gmail.com
stmt.Evict
, so there is no need to convertvictimTasksMap
to Slice