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-05-26 15:02:57 -03:00
2024-06-11 09:23:21 -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-09-03 20:39:33 -03:00
2024-09-19 23:55:10 -03:00
2024-09-27 13:31:29 -03:00
2024-09-09 22:25:54 -03:00
2024-09-30 13:27:29 -03:00
2024-06-22 22:43:57 -03:00
2024-09-27 10:33:17 -03:00
2024-05-26 15:02:57 -03:00
2024-08-08 10:14:29 -03:00
2024-05-26 15:02:57 -03:00
2024-08-08 10:14:29 -03:00
2024-09-27 13:31:29 -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-05-26 15:02:57 -03:00
2024-05-26 15:02:57 -03:00
2024-08-30 17:03:10 -03:00
2024-06-22 22:43:57 -03:00
2024-05-26 15:02:57 -03:00
2024-08-18 16:58:12 -03:00
2024-09-12 19:43:42 +00:00
2024-06-11 09:20:48 -03:00
2024-05-26 15:02:57 -03:00
2024-09-27 13:31:29 -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-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-09-23 09:14:26 -03:00
2024-05-26 15:02:57 -03:00
2024-05-26 15:02:57 -03:00
2024-07-13 14:09:46 -03:00
2024-09-19 23:55:10 -03:00
2024-07-24 09:58:42 -04: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-09-17 09:30:49 -03:00
2024-08-30 17:03:10 -03:00
2024-05-26 15:02:57 -03:00
2024-02-19 16:28:06 -03:00
2024-05-09 23:18:53 -03:00