Skip to content

Replace sort.Strings and sort.Ints with faster slices.Sort#11318

Merged
codesome merged 2 commits intoprometheus:mainfrom
bboreham:slices-sort
Sep 30, 2022
Merged

Replace sort.Strings and sort.Ints with faster slices.Sort#11318
codesome merged 2 commits intoprometheus:mainfrom
bboreham:slices-sort

Conversation

@bboreham
Copy link
Member

Use new experimental package golang.org/x/exp/slices.

slices.Sort works on values that are directly comparable, like strings, so avoids the overhad of an interface call to .Less().

Left tests unchanged, because they don't need the speed and it may be a cross-check that slices.Sort gives the same answer.

Follows on from #11054.

Use new experimental package `golang.org/x/exp/slices`.

slices.Sort works on values that are directly comparable, like strings,
so avoids the overhad of an interface call to `.Less()`.

Left tests unchanged, because they don't need the speed and it may be
a cross-check that slices.Sort gives the same answer.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
Use new experimental package `golang.org/x/exp/slices`.

slices.Sort works on values that are directly comparable, like ints,
so avoids the overhad of an interface call to `.Less()`.

Left tests unchanged, because they don't need the speed and it may be
a cross-check that slices.Sort gives the same answer.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
@codesome codesome merged commit 3330d85 into prometheus:main Sep 30, 2022
bboreham added a commit to bboreham/prometheus that referenced this pull request Oct 1, 2022
This call was added by PR prometheus#11075 merged before prometheus#11318 which changed all
similar calls to `sort.Sort` into a faster one.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
LeviHarrison pushed a commit that referenced this pull request Oct 1, 2022
This call was added by PR #11075 merged before #11318 which changed all
similar calls to `sort.Sort` into a faster one.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
charleskorn added a commit to grafana/mimir that referenced this pull request Dec 12, 2022
#3639 (comment),
prometheus/prometheus#11054, and
prometheus/prometheus#11318 all show
substantial performance improvements when using slices.Sort over
sort.Strings.

I've also added a linting rule to catch usage of sort.Strings and
sort.Ints in the future. (We don't currently use sort.Ints anywhere.)

We could also replace sort.Float64s with slices.Sort, however, this
requires more careful consideration as the documentation for
slices.Sort warns that it may not handle NaN values correctly.
charleskorn added a commit to grafana/mimir that referenced this pull request Dec 15, 2022
#3639 (comment),
prometheus/prometheus#11054, and
prometheus/prometheus#11318 all show
substantial performance improvements when using slices.Sort over
sort.Strings.

I've also added a linting rule to catch usage of sort.Strings and
sort.Ints in the future. (We don't currently use sort.Ints anywhere.)

We could also replace sort.Float64s with slices.Sort, however, this
requires more careful consideration as the documentation for
slices.Sort warns that it may not handle NaN values correctly.
pracucci pushed a commit to grafana/mimir that referenced this pull request Dec 15, 2022
* Use slices.Sort instead of sort.Strings or sort.Ints.

#3639 (comment),
prometheus/prometheus#11054, and
prometheus/prometheus#11318 all show
substantial performance improvements when using slices.Sort over
sort.Strings.

I've also added a linting rule to catch usage of sort.Strings and
sort.Ints in the future. (We don't currently use sort.Ints anywhere.)

We could also replace sort.Float64s with slices.Sort, however, this
requires more careful consideration as the documentation for
slices.Sort warns that it may not handle NaN values correctly.

* Remove unnecessary comment.

* Rename benchmarks file.

* Add benchmark for BinaryReader.LabelNames().

* Add benchmark for LabelValues().

* Modify mergeExemplarQueryResponses benchmark to exercise merging exemplars with different sets of labels.
masonmei pushed a commit to udmire/mimir that referenced this pull request Dec 16, 2022
…fana#3690)

* Use slices.Sort instead of sort.Strings or sort.Ints.

grafana#3639 (comment),
prometheus/prometheus#11054, and
prometheus/prometheus#11318 all show
substantial performance improvements when using slices.Sort over
sort.Strings.

I've also added a linting rule to catch usage of sort.Strings and
sort.Ints in the future. (We don't currently use sort.Ints anywhere.)

We could also replace sort.Float64s with slices.Sort, however, this
requires more careful consideration as the documentation for
slices.Sort warns that it may not handle NaN values correctly.

* Remove unnecessary comment.

* Rename benchmarks file.

* Add benchmark for BinaryReader.LabelNames().

* Add benchmark for LabelValues().

* Modify mergeExemplarQueryResponses benchmark to exercise merging exemplars with different sets of labels.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants