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

[YUNIKORN-2638] Simplify finalizeNodes and finalizePods #949

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

steinsgateted
Copy link
Contributor

What is this PR for?

  • Change map[types.UID]*v1.Pod / map[string]*v1.Node to map[types.UID]struct{}.
    Reduce the memory footprint of map, because struct{} is zero-size and does not occupy any additional space.

  • Fixed map length to avoid reallocation of memory

What type of PR is it?

  • - Bug Fix
  • - Improvement
  • - Feature
  • - Documentation
  • - Hot Fix
  • - Refactoring

Todos

  • - Task

What is the Jira issue?

https://issues.apache.org/jira/browse/YUNIKORN-2638

How should this be tested?

Screenshots (if appropriate)

Questions:

  • - The licenses files need update.
  • - There is breaking changes for older versions.
  • - It needs documentation.

@steinsgateted steinsgateted self-assigned this Feb 4, 2025
Copy link

codecov bot commented Feb 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 68.04%. Comparing base (6fee122) to head (6003ea7).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #949      +/-   ##
==========================================
+ Coverage   68.02%   68.04%   +0.02%     
==========================================
  Files          70       70              
  Lines        9195     9195              
==========================================
+ Hits         6255     6257       +2     
+ Misses       2733     2731       -2     
  Partials      207      207              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@pbacsko pbacsko self-requested a review February 5, 2025 13:35
Copy link
Contributor

@pbacsko pbacsko left a comment

Choose a reason for hiding this comment

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

+1

Copy link
Contributor

@chenyulin0719 chenyulin0719 left a comment

Choose a reason for hiding this comment

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

+1 LGTM

@@ -1621,9 +1621,9 @@ func (ctx *Context) finalizeNodes(existingNodes []*v1.Node) error {
}

// convert the node list into a map
nodeMap := make(map[string]*v1.Node)
nodeMap := make(map[string]struct{}, len(nodes))
Copy link
Contributor

@wilfred-s wilfred-s Feb 7, 2025

Choose a reason for hiding this comment

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

From a readability perspective I would prefer nodeMap := make(map[string]bool, len(nodes)) and set true in 1626
Then at line 1631 the check simply becomes if !nodeMap[node.Name] {

Size (~5% more) and speed wise (not measurable unless the map has millions of entries) it does not make a difference when you consider what we use it for.

Copy link
Contributor

@chenyulin0719 chenyulin0719 left a comment

Choose a reason for hiding this comment

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

From a readability perspective I would prefer nodeMap := make(map[string]bool, len(nodes)) and set true in 1626

I'm +1 on @wilfred-s's suggestion. I prefer readability over small performance enhancements too. @steinsgateted Could you make change for it?

@pbacsko
Copy link
Contributor

pbacsko commented Feb 14, 2025

I'm +1 on @wilfred-s's suggestion. I prefer readability over small performance enhancements too. @steinsgateted Could you make change for it?

Same here, I also vote for map[string]bool.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants