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

replace "golang.org/x/exp" with standard libraries #823

Merged
merged 1 commit into from
Jan 31, 2025

Conversation

apocelipes
Copy link
Contributor

What does this do?

Since gocron requires go1.21.0+, we can replace "golang.org/x/exp/maps" and "golang.org/x/exp/slices" with the standard libraries "maps" and "slices". BTW, "golang.org/x/exp/slices" now is only a wrapper of "slice".

Which issue(s) does this PR fix/relate to?

List any changes that modify/break current functionality

Have you included tests for your changes?

Did you document any new/modified functionality?

Notes

"removeSliceDuplicatesInt" could also get some performance benifits:

func BenchmarkRemoveSliceDuplicatesInt(b *testing.B) {
	for range b.N {
		removeSliceDuplicatesInt([]int{1, 4, 5, 4, 6, 2, 3})
	}
}
goos: windows
goarch: amd64
pkg: bench
cpu: Intel(R) Core(TM) i5-10200H CPU @ 2.40GHz
                           │     old      │                 new                 │
                           │    sec/op    │   sec/op     vs base                │
RemoveSliceDuplicatesInt-8   285.00n ± 1%   29.75n ± 0%  -89.56% (p=0.000 n=10)

                           │    old     │                new                 │
                           │    B/op    │   B/op     vs base                 │
RemoveSliceDuplicatesInt-8   96.00 ± 0%   0.00 ± 0%  -100.00% (p=0.000 n=10)

                           │    old     │                 new                 │
                           │ allocs/op  │ allocs/op   vs base                 │
RemoveSliceDuplicatesInt-8   3.000 ± 0%   0.000 ± 0%  -100.00% (p=0.000 n=10)

As an added benefit, there is now no need to sort the results of “removeSliceDuplicatesInt” because they are already sorted.

Copy link
Contributor

@JohnRoesler JohnRoesler left a comment

Choose a reason for hiding this comment

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

Thanks for taking the time to do this!

@JohnRoesler JohnRoesler merged commit 0c4a1a3 into go-co-op:v2 Jan 31, 2025
3 checks passed
@apocelipes apocelipes deleted the replace-slices branch January 31, 2025 15:20
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.

2 participants