Skip to content

Commit

Permalink
objstorageprovider: reuse buf from pooled remoteHandle
Browse files Browse the repository at this point in the history
During heavy reads of remote files, the `r.buffered.data = make([]byte, length)`
line was observed to account for more than half of CRDB's total space allocations.
  • Loading branch information
dt committed Jun 19, 2024
1 parent 41441bc commit 71d59d6
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion objstorage/objstorageprovider/remote_readable.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (r *remoteReadable) NewReadHandle(
ctx context.Context, readBeforeSize objstorage.ReadBeforeSize,
) objstorage.ReadHandle {
rh := remoteReadHandlePool.Get().(*remoteReadHandle)
*rh = remoteReadHandle{readable: r, readBeforeSize: readBeforeSize}
*rh = remoteReadHandle{readable: r, readBeforeSize: readBeforeSize, buffered: rh.buffered}
rh.readAheadState = makeReadaheadState(remoteMaxReadaheadSize)
return rh
}
Expand Down Expand Up @@ -250,7 +250,9 @@ func (r *remoteReadHandle) readToBuffer(ctx context.Context, offset int64, lengt

// Close is part of the objstorage.ReadHandle interface.
func (r *remoteReadHandle) Close() error {
buf := r.buffered.data[:0]
*r = remoteReadHandle{}
r.buffered.data = buf
remoteReadHandlePool.Put(r)
return nil
}
Expand Down

0 comments on commit 71d59d6

Please sign in to comment.