Skip to content

refactor: use strings.Builder to replace string concatenation - #5495

Merged
volcano-sh-bot merged 1 commit into
volcano-sh:masterfrom
DSFans2014:refact/string_format
Jun 29, 2026
Merged

refactor: use strings.Builder to replace string concatenation#5495
volcano-sh-bot merged 1 commit into
volcano-sh:masterfrom
DSFans2014:refact/string_format

Conversation

@DSFans2014

Copy link
Copy Markdown
Member

What type of PR is this?

What this PR does / why we need it:

To improve performance, replace the inefficient string concatenation (+=) with strings.Builder

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?


Copilot AI review requested due to automatic review settings June 24, 2026 04:28
@volcano-sh-bot volcano-sh-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jun 24, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the String() methods across several files (cluster_info.go, node_info.go, cache.go, and session.go) to use strings.Builder and fmt.Fprintf instead of string concatenation, which improves memory efficiency. However, a critical syntax error was introduced in pkg/scheduler/api/cluster_info.go due to an extra closing parenthesis in a fmt.Fprintf call, which will cause a compilation failure.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread pkg/scheduler/api/cluster_info.go Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors several String() implementations in the scheduler code to reduce allocations by replacing repeated string concatenation/fmt.Sprintf chains with strings.Builder.

Changes:

  • Update Session.String() to write into a strings.Builder via fmt.Fprintf.
  • Update SchedulerCache.String() to build output via strings.Builder (WriteString + fmt.Fprintf).
  • Update NodeInfo.String() and ClusterInfo.String() to accumulate task/node/job lines via strings.Builder.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
pkg/scheduler/framework/session.go Switches session string rendering to strings.Builder.
pkg/scheduler/cache/cache.go Switches cache string rendering to strings.Builder.
pkg/scheduler/api/node_info.go Switches node task list rendering in String() to strings.Builder.
pkg/scheduler/api/cluster_info.go Switches cluster snapshot string rendering to strings.Builder (currently introduces a compile error).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/scheduler/api/cluster_info.go Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment on lines 624 to +626
return fmt.Sprintf("Node (%s): allocatable<%v> idle <%v>, used <%v>, releasing <%v>, oversubscribution <%v>, "+
"state <phase %s, reaseon %s>, oversubscributionNode <%v>, offlineJobEvicting <%v>,taints <%v>%s, imageStates %v",
ni.Name, ni.Allocatable, ni.Idle, ni.Used, ni.Releasing, ni.OversubscriptionResource, ni.State.Phase, ni.State.Reason, ni.OversubscriptionNode, ni.OfflineJobEvicting, ni.Node.Spec.Taints, tasks, ni.ImageStates)
ni.Name, ni.Allocatable, ni.Idle, ni.Used, ni.Releasing, ni.OversubscriptionResource, ni.State.Phase, ni.State.Reason, ni.OversubscriptionNode, ni.OfflineJobEvicting, ni.Node.Spec.Taints, b.String(), ni.ImageStates)
Signed-off-by: james <open4pd@4paradigm.com>
@DSFans2014
DSFans2014 force-pushed the refact/string_format branch from 71e9aca to b1df5d8 Compare June 25, 2026 07:40
@volcano-sh-bot volcano-sh-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 25, 2026
@JesseStutler

Copy link
Copy Markdown
Member

/approve
/lgtm
Cool, thanks for your contribution

@volcano-sh-bot volcano-sh-bot added the lgtm Indicates that a PR is ready to be merged. label Jun 29, 2026
@volcano-sh-bot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: JesseStutler

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details 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 the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 29, 2026
@volcano-sh-bot
volcano-sh-bot merged commit 8bcdc6f into volcano-sh:master Jun 29, 2026
33 checks passed
@DSFans2014
DSFans2014 deleted the refact/string_format branch June 29, 2026 08:32
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. lgtm Indicates that a PR is ready to be merged. 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.

4 participants