Skip to content

Commit

Permalink
Prevent unnecessary safecopy in iterator parseKV (dgraph-io#971)
Browse files Browse the repository at this point in the history
The previous implementation of parseKV would copy over the value slice
every time we iterate, which is not necessary. The value slice should be
copied only when we return the result of point lookups. The proposed patch
removes safeCopy call from the iterator.
  • Loading branch information
Ibrahim Jarif authored Aug 10, 2019
1 parent 9d7b751 commit 74ed6da
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions table/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ func (itr *blockIterator) parseKV(h header) {
"Pos:%d Len:%d EndOffset:%d Header:%v", itr.pos, len(itr.data), valEndOffset, h)
return
}
// TODO (ibrahim): Can we avoid this copy?
itr.val = y.SafeCopy(itr.val, itr.data[itr.pos:valEndOffset])

itr.val = itr.data[itr.pos:valEndOffset]
// Set pos to the end of current entry.
itr.pos = valEndOffset
}
Expand Down
2 changes: 1 addition & 1 deletion txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ func (txn *Txn) Get(key []byte) (item *Item, rerr error) {
item.meta = vs.Meta
item.userMeta = vs.UserMeta
item.db = txn.db
item.vptr = vs.Value // TODO: Do we need to copy this over?
item.vptr = y.SafeCopy(item.vptr, vs.Value)
item.txn = txn
item.expiresAt = vs.ExpiresAt
return item, nil
Expand Down

0 comments on commit 74ed6da

Please sign in to comment.