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

*: adopt "slices" stdlib package for sorting #124363

Merged
merged 6 commits into from
May 20, 2024

Conversation

nvanbenschoten
Copy link
Member

This PR adopts the new "slices" package for sorting, where doing so makes sense. This package was added to the Go standard library in Go 1.21. It uses generics to improve the ergonomics and performance of sorting and searching related tasks.

@kvoli assigning you as a reviewer because allocator-related code seems to be the biggest user of sorting around.

See individual commits.

@nvanbenschoten nvanbenschoten requested a review from kvoli May 17, 2024 19:29
@nvanbenschoten nvanbenschoten requested review from a team as code owners May 17, 2024 19:29
@nvanbenschoten nvanbenschoten requested review from abarganier, nameisbhaskar, vidit-bhat, DrewKimball, dt and wenyihu6 and removed request for a team May 17, 2024 19:29
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@nvanbenschoten nvanbenschoten force-pushed the nvanbenschoten/slicesPkg branch 2 times, most recently from 104d9d7 to 7ee1c41 Compare May 17, 2024 19:59
Copy link
Collaborator

@kvoli kvoli left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 7 of 7 files at r1, 12 of 12 files at r2, 1 of 1 files at r3, 20 of 20 files at r4, 23 of 23 files at r5, 1 of 1 files at r6, 6 of 6 files at r7, 38 of 38 files at r8, 11 of 11 files at r9, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @abarganier, @DrewKimball, @dt, @nameisbhaskar, @nvanbenschoten, @vidit-bhat, and @wenyihu6)


pkg/sql/sem/tree/datum.go line 4817 at r7 (raw file):

func (d *DTuple) sort(ctx CompareContext) {
	if !d.sorted {
		lessFn := func(a, b Datum) int {

nit: consider rename to sortFn or similar.

The "cmp" package was added to the stdlib in Go 1.21.

Epic: None
Release note: None
The "slices" package was added to the stdlib in Go 1.21.

Epic: None
Release note: None
This commit replaces some of usages of sort.IsSorted with uses of
slices.IsSortedFunc, where doing so makes sense. As of Go 1.21, the docs
on sort.IsSorted say:
> Note: in many situations, the newer slices.IsSortedFunc function is
> more ergonomic and runs faster.

Epic: None
Release note: None
This commit replaces some of usages of sort.SliceIsSorted with uses of
slices.IsSortedFunc, where doing so makes sense. As of Go 1.21, the docs
on sort.SliceIsSorted say:
> Note: in many situations, the newer slices.IsSortedFunc function is
> more ergonomic and runs faster.

Epic: None
Release note: None
This commit replaces some of usages of sort.Slice with uses of
slices.SortFunc, where doing so makes sense. As of Go 1.21, the docs
on sort.Slice say:
> Note: in many situations, the newer slices.SortFunc function is
> more ergonomic and runs faster.

This commit only makes these changes in production kv code for now,
because replacing the other 200 or so uses of sort.Slice would be a lot
of churn with less benefit.

Epic: None
Release note: None
This commit replaces some of usages of sort.Slice with uses of
slices.Sort, where doing so makes sense. As of Go 1.21, the docs
on sort.Slice say:
> Note: in many situations, the newer slices.SortFunc function is
> more ergonomic and runs faster.

Epic: None
Release note: None
Copy link
Member Author

@nvanbenschoten nvanbenschoten left a comment

Choose a reason for hiding this comment

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

TFTR!

bors r=kvoli

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @abarganier, @DrewKimball, @dt, @kvoli, @nameisbhaskar, @vidit-bhat, and @wenyihu6)


pkg/sql/sem/tree/datum.go line 4817 at r7 (raw file):

Previously, kvoli (Austen) wrote…

nit: consider rename to sortFn or similar.

Done.

@craig craig bot merged commit f601b7b into cockroachdb:master May 20, 2024
21 of 22 checks passed
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.

None yet

3 participants