Skip to content

perf: better string concatenation#9705

Merged
kaovilai merged 11 commits intovelero-io:mainfrom
emirot:perf/string_concat
Apr 16, 2026
Merged

perf: better string concatenation#9705
kaovilai merged 11 commits intovelero-io:mainfrom
emirot:perf/string_concat

Conversation

@emirot
Copy link
Copy Markdown
Contributor

@emirot emirot commented Apr 10, 2026

Thank you for contributing to Velero!

Please add a summary of your change

Better practice and newer version of golinci-lint will raise an issue
like so

concat-loop: string concatenation in a loop (perfsprint)

Does your change fix a particular issue?

No
Fixes #(issue)

Please indicate you've done the following:

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 60.98%. Comparing base (4d9bd91) to head (ea2b55c).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #9705   +/-   ##
=======================================
  Coverage   60.97%   60.98%           
=======================================
  Files         384      384           
  Lines       36609    36612    +3     
=======================================
+ Hits        22322    22327    +5     
+ Misses      12678    12677    -1     
+ Partials     1609     1608    -1     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

kaovilai
kaovilai previously approved these changes Apr 14, 2026
Comment thread pkg/util/csi/volume_snapshot.go Outdated
@emirot emirot force-pushed the perf/string_concat branch from 2e2aab6 to 8bf739b Compare April 14, 2026 18:23
@github-actions github-actions Bot added Dependencies Pull requests that update a dependency file has-unit-tests labels Apr 14, 2026
@emirot emirot force-pushed the perf/string_concat branch from 8bf739b to 5b1094a Compare April 14, 2026 18:25
@emirot
Copy link
Copy Markdown
Contributor Author

emirot commented Apr 14, 2026

@kaovilai could you please take a second look

Comment thread pkg/util/kube/pvc_pv.go Outdated
Comment thread pkg/util/kube/pod.go Outdated
@emirot emirot force-pushed the perf/string_concat branch from fed4c36 to 8e2d4f0 Compare April 15, 2026 19:10
@emirot
Copy link
Copy Markdown
Contributor Author

emirot commented Apr 15, 2026

@blackpiglet I have updated please squash when merging

Comment thread pkg/util/kube/pvc_pv.go Outdated
Comment thread pkg/util/kube/pod.go Outdated
emirot and others added 10 commits April 15, 2026 21:10
Signed-off-by: emirot <emirot.nolan@gmail.com>
Signed-off-by: nolanemirot <nolan.emirot@broadcom.com>
Signed-off-by: emirot <emirot.nolan@gmail.com>
…elero-io#9693)

* Enhance backup deletion logic to handle tarball download failures and clean up associated CSI VolumeSnapshotContents
Signed-off-by: Priyansh Choudhary <im1706@gmail.com>

* added changelog
Signed-off-by: Priyansh Choudhary <im1706@gmail.com>

* Refactor error handling in backup deletion
Signed-off-by: Priyansh Choudhary <im1706@gmail.com>

* Refactor backup deletion logic to skip CSI snapshot cleanup on tarball download failure
Signed-off-by: Priyansh Choudhary <im1706@gmail.com>

* prevent backup deletion when errors occur
Signed-off-by: Priyansh Choudhary <im1706@gmail.com>

* added logger
Signed-off-by: Priyansh Choudhary <im1706@gmail.com>
Signed-off-by: emirot <emirot.nolan@gmail.com>
Signed-off-by: emirot <emirot.nolan@gmail.com>
…ion (velero-io#9700)

* Add delay to avoid race conditions during VolumeSnapshotContent deletion
Signed-off-by: Priyansh Choudhary <im1706@gmail.com>

* updated changelog
Signed-off-by: Priyansh Choudhary <im1706@gmail.com>

* Updated Changelog
Signed-off-by: Priyansh Choudhary <im1706@gmail.com>
Signed-off-by: emirot <emirot.nolan@gmail.com>
Signed-off-by: Lyndon-Li <lyonghui@vmware.com>
Signed-off-by: emirot <emirot.nolan@gmail.com>
Signed-off-by: Lyndon-Li <lyonghui@vmware.com>
Signed-off-by: emirot <emirot.nolan@gmail.com>
Signed-off-by: Lyndon-Li <lyonghui@vmware.com>
Signed-off-by: emirot <emirot.nolan@gmail.com>
Signed-off-by: Lyndon-Li <lyonghui@vmware.com>
Signed-off-by: emirot <emirot.nolan@gmail.com>
Update the community page to add the correct links to community meeting
and meeting notes.
I also removed the referece of google group as I confirmed the last
message was sent 2 years ago.

Signed-off-by: Daniel Jiang <daniel.jiang@broadcom.com>
Signed-off-by: emirot <emirot.nolan@gmail.com>
Signed-off-by: emirot <emirot.nolan@gmail.com>
@emirot emirot force-pushed the perf/string_concat branch from ae84800 to 60597b9 Compare April 16, 2026 04:10
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors several diagnostic/string-building helpers to avoid inefficient string concatenation patterns that newer golangci-lint/perfsprint versions can flag.

Changes:

  • Switch DiagnosePVC, DiagnosePod, and DiagnoseVS to build output via strings.Builder + fmt.Fprintf.
  • Update GetPodTerminateMessage to use strings.Builder and add the needed import.
  • Add an unreleased changelog entry for the performance-focused refactor.

Reviewed changes

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

File Description
pkg/util/kube/pvc_pv.go Refactors PVC diagnostic string construction to use strings.Builder.
pkg/util/kube/pod.go Uses strings.Builder for pod termination/diagnostic message assembly; adds strings import.
pkg/util/csi/volume_snapshot.go Refactors VolumeSnapshot diagnostic string construction to use strings.Builder.
changelogs/unreleased/9705-emirot Adds changelog entry describing the performance improvement.

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

Comment thread pkg/util/kube/pod.go
if containerStatus.State.Terminated != nil {
if containerStatus.State.Terminated.Message != "" {
message += containerStatus.State.Terminated.Message + "/"
message.WriteString(containerStatus.State.Terminated.Message + "/")
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

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

Inside the loop, this still performs string concatenation (Terminated.Message + "/"), which creates a new temporary string on every iteration and may continue to trigger the concat-loop lint/performance warning. Prefer writing the message and delimiter separately (e.g., write the message then write the "/" delimiter) to avoid per-iteration allocations.

Suggested change
message.WriteString(containerStatus.State.Terminated.Message + "/")
message.WriteString(containerStatus.State.Terminated.Message)
message.WriteString("/")

Copilot uses AI. Check for mistakes.
Comment thread pkg/util/kube/pod.go Outdated
Comment thread pkg/util/csi/volume_snapshot.go Outdated
@kaovilai kaovilai merged commit fc6361b into velero-io:main Apr 16, 2026
62 checks passed
blackpiglet pushed a commit to blackpiglet/velero that referenced this pull request Apr 16, 2026
* perf: better string concatenation

Signed-off-by: emirot <emirot.nolan@gmail.com>
Signed-off-by: nolanemirot <nolan.emirot@broadcom.com>
Signed-off-by: emirot <emirot.nolan@gmail.com>

* fix: backup deletion silently succeeds when tarball download fails (velero-io#9693)

* Enhance backup deletion logic to handle tarball download failures and clean up associated CSI VolumeSnapshotContents
Signed-off-by: Priyansh Choudhary <im1706@gmail.com>

* added changelog
Signed-off-by: Priyansh Choudhary <im1706@gmail.com>

* Refactor error handling in backup deletion
Signed-off-by: Priyansh Choudhary <im1706@gmail.com>

* Refactor backup deletion logic to skip CSI snapshot cleanup on tarball download failure
Signed-off-by: Priyansh Choudhary <im1706@gmail.com>

* prevent backup deletion when errors occur
Signed-off-by: Priyansh Choudhary <im1706@gmail.com>

* added logger
Signed-off-by: Priyansh Choudhary <im1706@gmail.com>
Signed-off-by: emirot <emirot.nolan@gmail.com>

* perf: better string concatenation

Signed-off-by: emirot <emirot.nolan@gmail.com>

* Add delay to avoid race conditions during VolumeSnapshotContent deletion (velero-io#9700)

* Add delay to avoid race conditions during VolumeSnapshotContent deletion
Signed-off-by: Priyansh Choudhary <im1706@gmail.com>

* updated changelog
Signed-off-by: Priyansh Choudhary <im1706@gmail.com>

* Updated Changelog
Signed-off-by: Priyansh Choudhary <im1706@gmail.com>
Signed-off-by: emirot <emirot.nolan@gmail.com>

* block data mover design

Signed-off-by: Lyndon-Li <lyonghui@vmware.com>
Signed-off-by: emirot <emirot.nolan@gmail.com>

* block data mover design

Signed-off-by: Lyndon-Li <lyonghui@vmware.com>
Signed-off-by: emirot <emirot.nolan@gmail.com>

* irregular volume size

Signed-off-by: Lyndon-Li <lyonghui@vmware.com>
Signed-off-by: emirot <emirot.nolan@gmail.com>

* block data mover design

Signed-off-by: Lyndon-Li <lyonghui@vmware.com>
Signed-off-by: emirot <emirot.nolan@gmail.com>

* Update the "community" page of website (velero-io#9722)

Update the community page to add the correct links to community meeting
and meeting notes.
I also removed the referece of google group as I confirmed the last
message was sent 2 years ago.

Signed-off-by: Daniel Jiang <daniel.jiang@broadcom.com>
Signed-off-by: emirot <emirot.nolan@gmail.com>

* perf: better string concatenation

Signed-off-by: emirot <emirot.nolan@gmail.com>

---------

Signed-off-by: emirot <emirot.nolan@gmail.com>
Signed-off-by: nolanemirot <nolan.emirot@broadcom.com>
Signed-off-by: Priyansh Choudhary <im1706@gmail.com>
Signed-off-by: Lyndon-Li <lyonghui@vmware.com>
Signed-off-by: Daniel Jiang <daniel.jiang@broadcom.com>
Co-authored-by: Priyansh Choudhary <im1706@gmail.com>
Co-authored-by: nolanemirot <nolan.emirot@broadcom.com>
Co-authored-by: Lyndon-Li <lyonghui@vmware.com>
Co-authored-by: Daniel Jiang <daniel.jiang@broadcom.com>
priyansh17 added a commit to priyansh17/velero that referenced this pull request Apr 23, 2026
* perf: better string concatenation

Signed-off-by: emirot <emirot.nolan@gmail.com>
Signed-off-by: nolanemirot <nolan.emirot@broadcom.com>
Signed-off-by: emirot <emirot.nolan@gmail.com>

* fix: backup deletion silently succeeds when tarball download fails (velero-io#9693)

* Enhance backup deletion logic to handle tarball download failures and clean up associated CSI VolumeSnapshotContents
Signed-off-by: Priyansh Choudhary <im1706@gmail.com>

* added changelog
Signed-off-by: Priyansh Choudhary <im1706@gmail.com>

* Refactor error handling in backup deletion
Signed-off-by: Priyansh Choudhary <im1706@gmail.com>

* Refactor backup deletion logic to skip CSI snapshot cleanup on tarball download failure
Signed-off-by: Priyansh Choudhary <im1706@gmail.com>

* prevent backup deletion when errors occur
Signed-off-by: Priyansh Choudhary <im1706@gmail.com>

* added logger
Signed-off-by: Priyansh Choudhary <im1706@gmail.com>
Signed-off-by: emirot <emirot.nolan@gmail.com>

* perf: better string concatenation

Signed-off-by: emirot <emirot.nolan@gmail.com>

* Add delay to avoid race conditions during VolumeSnapshotContent deletion (velero-io#9700)

* Add delay to avoid race conditions during VolumeSnapshotContent deletion
Signed-off-by: Priyansh Choudhary <im1706@gmail.com>

* updated changelog
Signed-off-by: Priyansh Choudhary <im1706@gmail.com>

* Updated Changelog
Signed-off-by: Priyansh Choudhary <im1706@gmail.com>
Signed-off-by: emirot <emirot.nolan@gmail.com>

* block data mover design

Signed-off-by: Lyndon-Li <lyonghui@vmware.com>
Signed-off-by: emirot <emirot.nolan@gmail.com>

* block data mover design

Signed-off-by: Lyndon-Li <lyonghui@vmware.com>
Signed-off-by: emirot <emirot.nolan@gmail.com>

* irregular volume size

Signed-off-by: Lyndon-Li <lyonghui@vmware.com>
Signed-off-by: emirot <emirot.nolan@gmail.com>

* block data mover design

Signed-off-by: Lyndon-Li <lyonghui@vmware.com>
Signed-off-by: emirot <emirot.nolan@gmail.com>

* Update the "community" page of website (velero-io#9722)

Update the community page to add the correct links to community meeting
and meeting notes.
I also removed the referece of google group as I confirmed the last
message was sent 2 years ago.

Signed-off-by: Daniel Jiang <daniel.jiang@broadcom.com>
Signed-off-by: emirot <emirot.nolan@gmail.com>

* perf: better string concatenation

Signed-off-by: emirot <emirot.nolan@gmail.com>

---------

Signed-off-by: emirot <emirot.nolan@gmail.com>
Signed-off-by: nolanemirot <nolan.emirot@broadcom.com>
Signed-off-by: Priyansh Choudhary <im1706@gmail.com>
Signed-off-by: Lyndon-Li <lyonghui@vmware.com>
Signed-off-by: Daniel Jiang <daniel.jiang@broadcom.com>
Co-authored-by: Priyansh Choudhary <im1706@gmail.com>
Co-authored-by: nolanemirot <nolan.emirot@broadcom.com>
Co-authored-by: Lyndon-Li <lyonghui@vmware.com>
Co-authored-by: Daniel Jiang <daniel.jiang@broadcom.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Dependencies Pull requests that update a dependency file has-changelog has-unit-tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants