Skip to content

Disallow slow sorting #3981

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

Merged
merged 1 commit into from
May 28, 2025
Merged

Disallow slow sorting #3981

merged 1 commit into from
May 28, 2025

Conversation

StephenButtolph
Copy link
Contributor

Why this should be merged

sort.Slice is an old method of sorting that relies on reflection. The slices.Sort method is generic and runs faster.

How this works

This doesn't disallow sort entirely, as there are still some usages of the sort.Interface which are a bit more complex to change... Although we should probably change those as well eventually.

How this was tested

CI

Need to be documented in RELEASES.md?

No.

@Copilot Copilot AI review requested due to automatic review settings May 28, 2025 15:24
@StephenButtolph StephenButtolph requested a review from a team May 28, 2025 15:25
Copy link
Contributor

@Copilot 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

This PR replaces reflection-based sorting calls with the generic, faster slices.Sort and updates the linter to forbid the old patterns.

  • Swap out sort.Strings/sort.Slice for slices.Sort in tests
  • Update imports accordingly
  • Add a forbidigo rule to disallow sort.Slice/sort.Strings

Reviewed Changes

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

File Description
x/merkledb/view_iterator_test.go Replaced sort.Strings with slices.Sort and updated imports
vms/platformvm/validator_set_property_test.go Replaced sort.Slice call with slices.Sort and updated imports
.golangci.yml Added forbidigo exclusion for sort.Slice/sort.Strings

@StephenButtolph StephenButtolph enabled auto-merge May 28, 2025 15:27
@StephenButtolph StephenButtolph added this pull request to the merge queue May 28, 2025
Merged via the queue into master with commit a9ea4d6 May 28, 2025
25 checks passed
@StephenButtolph StephenButtolph deleted the disallow-slow-sorting branch May 28, 2025 16:19
@github-project-automation github-project-automation bot moved this to Done 🎉 in avalanchego May 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants