Skip to content

Commit 51b78eb

Browse files
got performance
1 parent b7f9bbd commit 51b78eb

File tree

4 files changed

+17
-32
lines changed

4 files changed

+17
-32
lines changed

algo/uidlist.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func IntersectCompressedWith(pack *pb.UidPack, afterUID uint64, v, o *pb.List) {
4343
if pack == nil {
4444
return
4545
}
46-
dec := codec.Decoder{Pack: pack}
46+
dec := codec.Decoder{Pack: pack, UnpackedBlocks: make(map[int][]uint64)}
4747
dec.Seek(afterUID, codec.SeekStart)
4848
n := dec.ApproxLen()
4949
m := len(v.Uids)

codec/codec.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,15 @@ type Decoder struct {
151151
Pack *pb.UidPack
152152
blockIdx int
153153
uids []uint64
154+
155+
UnpackedBlocks map[int][]uint64
154156
}
155157

156158
// NewDecoder returns a decoder for the given UidPack and properly initializes it.
157159
func NewDecoder(pack *pb.UidPack) *Decoder {
158160
decoder := &Decoder{
159-
Pack: pack,
161+
Pack: pack,
162+
UnpackedBlocks: make(map[int][]uint64),
160163
}
161164
decoder.Seek(0, SeekStart)
162165
return decoder
@@ -173,6 +176,11 @@ func (d *Decoder) UnpackBlock() []uint64 {
173176
if d.blockIdx >= len(d.Pack.Blocks) {
174177
return d.uids
175178
}
179+
180+
if val, ok := d.UnpackedBlocks[d.blockIdx]; ok {
181+
return val
182+
}
183+
176184
block := d.Pack.Blocks[d.blockIdx]
177185

178186
last := block.Base
@@ -207,6 +215,7 @@ func (d *Decoder) UnpackBlock() []uint64 {
207215
}
208216

209217
d.uids = d.uids[:block.NumUids]
218+
d.UnpackedBlocks[d.blockIdx] = append(make([]uint64, 0, len(d.uids)), d.uids...)
210219
return d.uids
211220
}
212221

posting/list.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func (it *pIterator) seek(l *List, afterUid, deleteBelowTs uint64) error {
141141
}
142142

143143
it.uidPosting = &pb.Posting{}
144-
it.dec = &codec.Decoder{Pack: it.plist.Pack}
144+
it.dec = &codec.Decoder{Pack: it.plist.Pack, UnpackedBlocks: make(map[int][]uint64)}
145145
it.uids = it.dec.Seek(it.afterUid, codec.SeekCurrent)
146146
it.uidx = 0
147147

@@ -1180,7 +1180,11 @@ func (l *List) Uids(opt ListOptions) (*pb.List, error) {
11801180
l.RUnlock()
11811181
return out, ErrTsTooOld
11821182
}
1183+
//if len(opt.Intersect.Uids) > 10*codec.ApproxLen(l.plist.Pack) {
1184+
// algo.IntersectCompressedWithAlternate(l.plist.Pack, opt.AfterUid, opt.Intersect, out)
1185+
//} else {
11831186
algo.IntersectCompressedWith(l.plist.Pack, opt.AfterUid, opt.Intersect, out)
1187+
//}
11841188
l.RUnlock()
11851189
return out, nil
11861190
}

worker/sort.go

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"encoding/hex"
2222
"sort"
2323
"strings"
24-
"time"
2524

2625
"github.com/golang/glog"
2726
"github.com/pkg/errors"
@@ -512,34 +511,7 @@ func processSort(ctx context.Context, ts *pb.SortMessage) (*pb.SortResult, error
512511
cctx, cancel := context.WithCancel(ctx)
513512
defer cancel()
514513

515-
resCh := make(chan *sortresult, 2)
516-
go func() {
517-
select {
518-
case <-time.After(3 * time.Millisecond):
519-
// Wait between ctx chan and time chan.
520-
case <-ctx.Done():
521-
resCh <- &sortresult{err: ctx.Err()}
522-
return
523-
}
524-
r := sortWithoutIndex(cctx, ts)
525-
resCh <- r
526-
}()
527-
528-
go func() {
529-
sr := sortWithIndex(cctx, ts)
530-
resCh <- sr
531-
}()
532-
533-
r := <-resCh
534-
if r.err == nil {
535-
cancel()
536-
// wait for other goroutine to get cancelled
537-
<-resCh
538-
} else {
539-
span.Annotatef(nil, "processSort error: %v", r.err)
540-
r = <-resCh
541-
}
542-
514+
r := sortWithIndex(cctx, ts)
543515
if r.err != nil {
544516
return nil, r.err
545517
}

0 commit comments

Comments
 (0)