Skip to content

Commit

Permalink
storage: defer putBuffer release in all cases
Browse files Browse the repository at this point in the history
This commit switches the remainder of the calls to putBuffer.release to be
deferred, instead of being manually called at the end of their function. The
comments mentioning that the defer was "measurably slower" were introduced in
4444618, which was before Go 1.14 optimized the performance of defer. Most of
these, including the more performance sensitive calls, were already switched
over to use defer in fbe8852.

Epic: None
Release note: None
  • Loading branch information
nvanbenschoten committed Aug 21, 2023
1 parent 1679936 commit aa0a9cc
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions pkg/storage/mvcc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2547,6 +2547,7 @@ func MVCCMerge(
metaKey := MakeMVCCMetadataKey(key)

buf := newPutBuffer()
defer buf.release()

// Every type flows through here, so we can't use the typed getters.
rawBytes := value.RawBytes
Expand All @@ -2566,7 +2567,6 @@ func MVCCMerge(
key, int64(len(rawBytes)), timestamp.WallTime))
}
}
buf.release()
return err
}

Expand Down Expand Up @@ -4342,6 +4342,7 @@ func MVCCResolveWriteIntent(
return false, 0, nil, err
}
iterAndBuf := GetBufUsingIter(iter)
defer iterAndBuf.Cleanup()
iterAndBuf.iter.SeekIntentGE(intent.Key, intent.Txn.ID)
// Production code will use a buffered writer, which makes the numBytes
// calculation accurate. Note that an inaccurate numBytes (e.g. 0 in the
Expand All @@ -4350,8 +4351,6 @@ func MVCCResolveWriteIntent(
beforeBytes := rw.BufferedSize()
ok, err = mvccResolveWriteIntent(ctx, rw, iterAndBuf.iter, ms, intent, iterAndBuf.buf)
numBytes = int64(rw.BufferedSize() - beforeBytes)
// Using defer would be more convenient, but it is measurably slower.
iterAndBuf.Cleanup()
return ok, numBytes, nil, err
}

Expand Down Expand Up @@ -5164,6 +5163,7 @@ func MVCCResolveWriteIntentRange(
if err != nil {
return 0, 0, nil, 0, err
}
defer engineIter.Close()
var mvccIter MVCCIterator
iterOpts := IterOptions{
KeyTypes: IterKeyTypePointsAndRanges,
Expand All @@ -5181,10 +5181,7 @@ func MVCCResolveWriteIntentRange(
mvccIter = newPebbleIteratorByCloning(engineIter.CloneContext(), iterOpts, StandardDurability)
}
iterAndBuf := GetBufUsingIter(mvccIter)
defer func() {
engineIter.Close()
iterAndBuf.Cleanup()
}()
defer iterAndBuf.Cleanup()
putBuf := iterAndBuf.buf
sepIter := &separatedIntentAndVersionIter{
engineIter: engineIter,
Expand Down

0 comments on commit aa0a9cc

Please sign in to comment.