1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-02-15 13:53:25 +02:00
Eng Zer Jun b8aef100f2
perf(changelog): improve changelog sort performance (#5161)
This commit removes the unnecessary slice copy in `sortEntries`, and
replaces `sort.Slice` [^1] with the new `slices.SortFunc` [^2].

As recommended by the Go documentation, `slices.SortFunc` is generally
faster because it uses generic, whereas `sort.Slice` relies on
reflection, which incurs additional allocations

The benchmark result from the newly added `Benchmark_sortEntries` show
approximately a 64% performance improvement.


Benchmark result:

```
                     │   old.txt    │               new.txt               │
                     │    sec/op    │   sec/op     vs base                │
_sortEntries/asc-16    16.458µ ± 1%   5.958µ ± 1%  -63.80% (p=0.000 n=10)
_sortEntries/desc-16   17.675µ ± 1%   6.020µ ± 0%  -65.94% (p=0.000 n=10)
geomean                 17.06µ        5.989µ       -64.89%

                     │   old.txt    │               new.txt                │
                     │     B/op     │     B/op      vs base                │
_sortEntries/asc-16    3.164Ki ± 0%   1.164Ki ± 0%  -63.21% (p=0.000 n=10)
_sortEntries/desc-16   3.422Ki ± 0%   1.164Ki ± 0%  -65.98% (p=0.000 n=10)
geomean                3.290Ki        1.164Ki       -64.62%

                     │  old.txt   │              new.txt               │
                     │ allocs/op  │ allocs/op   vs base                │
_sortEntries/asc-16    68.00 ± 0%   25.00 ± 0%  -63.24% (p=0.000 n=10)
_sortEntries/desc-16   72.00 ± 0%   25.00 ± 0%  -65.28% (p=0.000 n=10)
geomean                69.97        25.00       -64.27%
```

[^1]: https://pkg.go.dev/sort#Slice
[^2]: https://pkg.go.dev/slices#SortFunc

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2024-09-30 13:27:29 -03:00
..
2024-06-11 09:23:21 -03:00
2024-05-26 15:02:57 -03:00
2024-06-22 22:43:57 -03:00
2024-09-27 10:33:17 -03:00
2024-06-26 08:52:22 -03:00
2024-05-26 15:02:57 -03:00
2024-05-26 15:02:57 -03:00
2024-08-18 16:08:55 -03:00
2024-09-07 11:15:48 -03:00
2024-05-26 15:02:57 -03:00
2024-06-22 22:43:57 -03:00
2024-09-12 19:43:42 +00:00
2024-06-22 22:43:57 -03:00
2024-05-26 15:02:57 -03:00
2024-05-26 15:02:57 -03:00
2024-05-26 15:02:57 -03:00
2024-05-26 15:02:57 -03:00
2024-05-26 15:02:57 -03:00
2024-08-30 17:03:10 -03:00