From 71d59d67105795fbdf28c8a3060acf96eada1d04 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Sun, 26 May 2024 11:43:46 +0000 Subject: [PATCH] objstorageprovider: reuse buf from pooled remoteHandle 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. --- objstorage/objstorageprovider/remote_readable.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/objstorage/objstorageprovider/remote_readable.go b/objstorage/objstorageprovider/remote_readable.go index 1780ba51e8..cfa79c4de0 100644 --- a/objstorage/objstorageprovider/remote_readable.go +++ b/objstorage/objstorageprovider/remote_readable.go @@ -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 } @@ -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 }