Skip to content

Commit 0716dc4

Browse files
committed
Remove size calculation in posting list.
1 parent b47986a commit 0716dc4

File tree

1 file changed

+4
-28
lines changed

1 file changed

+4
-28
lines changed

posting/list.go

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"math"
2626
"sort"
2727
"sync/atomic"
28-
"unsafe"
2928

3029
"github.com/dgryski/go-farm"
3130
"github.com/golang/glog"
@@ -68,27 +67,15 @@ const (
6867

6968
type List struct {
7069
x.SafeMutex
71-
key []byte
72-
plist *pb.PostingList
73-
mutationMap map[uint64]*pb.PostingList
74-
minTs uint64 // commit timestamp of immutable layer, reject reads before this ts.
75-
estimatedSize int32
70+
key []byte
71+
plist *pb.PostingList
72+
mutationMap map[uint64]*pb.PostingList
73+
minTs uint64 // commit timestamp of immutable layer, reject reads before this ts.
7674

7775
pendingTxns int32 // Using atomic for this, to avoid locking in SetForDeletion operation.
7876
deleteMe int32 // Using atomic for this, to avoid expensive SetForDeletion operation.
7977
}
8078

81-
// calculateSize would give you the size estimate. This is expensive, so run it carefully.
82-
func (l *List) calculateSize() int32 {
83-
sz := int(unsafe.Sizeof(l))
84-
sz += l.plist.Size()
85-
sz += cap(l.key)
86-
for _, pl := range l.mutationMap {
87-
sz += 8 + pl.Size()
88-
}
89-
return int32(sz)
90-
}
91-
9279
type PIterator struct {
9380
pl *pb.PostingList
9481
uidPosting *pb.Posting
@@ -184,14 +171,6 @@ func NewPosting(t *pb.DirectedEdge) *pb.Posting {
184171
}
185172
}
186173

187-
func (l *List) EstimatedSize() int32 {
188-
size := atomic.LoadInt32(&l.estimatedSize)
189-
if size < 0 {
190-
return 0
191-
}
192-
return size
193-
}
194-
195174
// SetForDeletion will mark this List to be deleted, so no more mutations can be applied to this.
196175
// Ensure that we don't acquire any locks during a call to this function, so the LRU cache can
197176
// proceed smoothly.
@@ -328,7 +307,6 @@ func (l *List) addMutation(ctx context.Context, txn *Txn, t *pb.DirectedEdge) er
328307
}
329308

330309
l.updateMutationLayer(mpost)
331-
atomic.AddInt32(&l.estimatedSize, int32(mpost.Size()+16 /* various overhead */))
332310
atomic.AddInt32(&l.pendingTxns, 1)
333311
txn.AddKeys(string(l.key), conflictKey)
334312
return nil
@@ -375,7 +353,6 @@ func (l *List) commitMutation(startTs, commitTs uint64) error {
375353
}
376354
if commitTs == 0 {
377355
// Abort mutation.
378-
atomic.AddInt32(&l.estimatedSize, -1*int32(plist.Size()))
379356
delete(l.mutationMap, startTs)
380357
return nil
381358
}
@@ -688,7 +665,6 @@ func (l *List) rollup(readTs uint64) error {
688665

689666
l.minTs = maxCommitTs
690667
l.plist = final
691-
atomic.StoreInt32(&l.estimatedSize, l.calculateSize())
692668
return nil
693669
}
694670

0 commit comments

Comments
 (0)