Skip to content

Conversation

philippgille
Copy link
Owner

slices.SortFunc is recommended over sort.Slice and more performant.

Query duration decreased ~17% in our benchmark:

goos: linux
goarch: amd64
pkg: github.com/philippgille/chromem-go
cpu: 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
                                    │    after     │               after2                │
                                    │    sec/op    │    sec/op     vs base               │
Collection_Query_NoContent_100-8      109.9µ ±  1%   106.3µ ±  2%   -3.23% (p=0.002 n=6)
Collection_Query_NoContent_1000-8     536.8µ ±  1%   490.7µ ±  1%   -8.60% (p=0.002 n=6)
Collection_Query_NoContent_5000-8     4.985m ± 15%   2.704m ±  5%  -45.76% (p=0.002 n=6)
Collection_Query_NoContent_25000-8    14.97m ± 10%   13.17m ± 11%  -11.99% (p=0.004 n=6)
Collection_Query_NoContent_100000-8   56.50m ± 11%   51.86m ± 13%   -8.21% (p=0.041 n=6)
Collection_Query_100-8                110.0µ ±  0%   106.8µ ±  0%   -2.91% (p=0.002 n=6)
Collection_Query_1000-8               536.8µ ±  0%   489.7µ ±  0%   -8.78% (p=0.002 n=6)
Collection_Query_5000-8               4.869m ±  5%   2.704m ±  6%  -44.46% (p=0.002 n=6)
Collection_Query_25000-8              15.01m ±  3%   13.05m ±  2%  -13.09% (p=0.002 n=6)
Collection_Query_100000-8             56.48m ±  4%   52.07m ±  5%   -7.81% (p=0.002 n=6)
geomean                               3.008m         2.492m        -17.13%

                                    │    after     │               after2               │
                                    │     B/op     │     B/op      vs base              │
Collection_Query_NoContent_100-8      6.330Ki ± 0%   6.235Ki ± 0%  -1.50% (p=0.002 n=6)
Collection_Query_NoContent_1000-8     34.83Ki ± 0%   34.74Ki ± 0%  -0.26% (p=0.002 n=6)
Collection_Query_NoContent_5000-8     162.8Ki ± 0%   162.7Ki ± 0%  -0.05% (p=0.002 n=6)
Collection_Query_NoContent_25000-8    794.8Ki ± 0%   794.7Ki ± 0%  -0.01% (p=0.002 n=6)
Collection_Query_NoContent_100000-8   3.057Mi ± 0%   3.057Mi ± 0%  -0.00% (p=0.002 n=6)
Collection_Query_100-8                6.329Ki ± 0%   6.234Ki ± 0%  -1.49% (p=0.002 n=6)
Collection_Query_1000-8               34.83Ki ± 0%   34.74Ki ± 0%  -0.26% (p=0.002 n=6)
Collection_Query_5000-8               162.8Ki ± 0%   162.7Ki ± 0%  -0.06% (p=0.002 n=6)
Collection_Query_25000-8              794.8Ki ± 0%   794.7Ki ± 0%  -0.01% (p=0.002 n=6)
Collection_Query_100000-8             3.057Mi ± 0%   3.057Mi ± 0%       ~ (p=0.065 n=6)
geomean                               155.0Ki        154.4Ki       -0.37%

                                    │   after    │              after2              │
                                    │ allocs/op  │ allocs/op   vs base              │
Collection_Query_NoContent_100-8      44.00 ± 0%   41.00 ± 0%  -6.82% (p=0.002 n=6)
Collection_Query_NoContent_1000-8     44.00 ± 0%   41.00 ± 0%  -6.82% (p=0.002 n=6)
Collection_Query_NoContent_5000-8     44.00 ± 0%   41.00 ± 0%  -6.82% (p=0.002 n=6)
Collection_Query_NoContent_25000-8    44.00 ± 0%   41.00 ± 0%  -6.82% (p=0.002 n=6)
Collection_Query_NoContent_100000-8   44.00 ± 0%   41.00 ± 0%  -6.82% (p=0.002 n=6)
Collection_Query_100-8                44.00 ± 0%   41.00 ± 0%  -6.82% (p=0.002 n=6)
Collection_Query_1000-8               44.00 ± 0%   41.00 ± 0%  -6.82% (p=0.002 n=6)
Collection_Query_5000-8               44.00 ± 0%   41.00 ± 0%  -6.82% (p=0.002 n=6)
Collection_Query_25000-8              44.00 ± 0%   41.00 ± 0%  -6.82% (p=0.002 n=6)
Collection_Query_100000-8             44.00 ± 0%   41.50 ± 1%  -5.68% (p=0.002 n=6)
geomean                               44.00        41.05       -6.71%

slices.SortFunc is recommended over sort.Slice and more performant
@philippgille philippgille merged commit 54b1857 into main Mar 17, 2024
@philippgille philippgille deleted the improve-query-sorting branch March 17, 2024 13:09
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.

1 participant