From fdc2d7751266c414ca51e1d2c8ba79d50dc8d237 Mon Sep 17 00:00:00 2001 From: Andrew Gillis Date: Fri, 8 Mar 2024 03:54:08 -0800 Subject: [PATCH] Faster multihash sort (#192) --- go.mod | 2 +- go.sum | 4 ++-- store/pebble/pebble.go | 10 +++------- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index d4d991a..e5d40a0 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/gammazero/radixtree v0.3.1 github.com/ipfs/go-cid v0.4.1 github.com/ipfs/go-log/v2 v2.5.1 - github.com/ipni/go-libipni v0.5.13 + github.com/ipni/go-libipni v0.5.14 github.com/libp2p/go-libp2p v0.33.0 github.com/mr-tron/base58 v1.2.0 github.com/multiformats/go-multihash v0.2.3 diff --git a/go.sum b/go.sum index 4c85aec..be866a5 100644 --- a/go.sum +++ b/go.sum @@ -74,8 +74,8 @@ github.com/ipfs/go-log/v2 v2.5.1 h1:1XdUzF7048prq4aBjDQQ4SL5RxftpRGdXhNRwKSAlcY= github.com/ipfs/go-log/v2 v2.5.1/go.mod h1:prSpmC1Gpllc9UYWxDiZDreBYw7zp4Iqp1kOLU9U5UI= github.com/ipld/go-ipld-prime v0.21.0 h1:n4JmcpOlPDIxBcY037SVfpd1G+Sj1nKZah0m6QH9C2E= github.com/ipld/go-ipld-prime v0.21.0/go.mod h1:3RLqy//ERg/y5oShXXdx5YIp50cFGOanyMctpPjsvxQ= -github.com/ipni/go-libipni v0.5.13 h1:4aE7c/DnTwEJNWQY33hYQqAZHkXCazdjUg8buNxM8as= -github.com/ipni/go-libipni v0.5.13/go.mod h1:dL/2YiaL7pVUmtwoa017M9i4bFqYTvehsZNASU22UXE= +github.com/ipni/go-libipni v0.5.14 h1:crJK8WRWajCv5K2kS7jXAhL5KnC4rYqdA8KFI2JCHCY= +github.com/ipni/go-libipni v0.5.14/go.mod h1:dL/2YiaL7pVUmtwoa017M9i4bFqYTvehsZNASU22UXE= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/klauspost/compress v1.17.6 h1:60eq2E/jlfwQXtvZEeBUYADs+BwKBWURIY+Gj2eRGjI= diff --git a/store/pebble/pebble.go b/store/pebble/pebble.go index 2ac0095..f4fa464 100644 --- a/store/pebble/pebble.go +++ b/store/pebble/pebble.go @@ -5,7 +5,7 @@ import ( "context" "errors" "io" - "sort" + "slices" "time" "github.com/cockroachdb/pebble" @@ -150,9 +150,7 @@ func (s *store) Put(v indexer.Value, mhs ...multihash.Multihash) error { // multihashes means their resulting keys will also be sorted. if len(mhs) > 1 { // Make a copy to reorder. - sort.Slice(mhs, func(i, j int) bool { - return bytes.Compare(mhs[i], mhs[j]) == -1 - }) + slices.SortFunc(mhs, func(a, b multihash.Multihash) int { return bytes.Compare(a, b) }) } keygen := s.p.leaseBlake3Keyer() @@ -203,9 +201,7 @@ func (s *store) Remove(v indexer.Value, mhs ...multihash.Multihash) error { // multihash key is a prefix plus the multihash itself, sorting the // multihashes means their resulting keys will also be sorted. if len(mhs) > 1 { - sort.Slice(mhs, func(i, j int) bool { - return bytes.Compare(mhs[i], mhs[j]) == -1 - }) + slices.SortFunc(mhs, func(a, b multihash.Multihash) int { return bytes.Compare(a, b) }) } keygen := s.p.leaseBlake3Keyer()