diff --git a/pkg/services/object/put/distributed.go b/pkg/services/object/put/distributed.go index 3b5f4ec5..e4566157 100644 --- a/pkg/services/object/put/distributed.go +++ b/pkg/services/object/put/distributed.go @@ -28,7 +28,7 @@ type distributedTarget struct { obj *objectSDK.Object objMeta object.ContentMeta - payload []byte + payload *payload nodeTargetInitializer func(nodeDesc) preparedObjectTarget @@ -122,7 +122,7 @@ func (t *distributedTarget) WriteHeader(obj *objectSDK.Object) error { } func (t *distributedTarget) Write(p []byte) (n int, err error) { - t.payload = append(t.payload, p...) + t.payload.Data = append(t.payload.Data, p...) return len(p), nil } @@ -133,7 +133,7 @@ func (t *distributedTarget) Close() (*transformer.AccessIdentifiers, error) { t.payload = nil }() - t.obj.SetPayload(t.payload) + t.obj.SetPayload(t.payload.Data) var err error diff --git a/pkg/services/object/put/pool.go b/pkg/services/object/put/pool.go index 70527322..5726856e 100644 --- a/pkg/services/object/put/pool.go +++ b/pkg/services/object/put/pool.go @@ -6,15 +6,19 @@ import ( const defaultAllocSize = 1024 +type payload struct { + Data []byte +} + var putBytesPool = &sync.Pool{ - New: func() any { return make([]byte, 0, defaultAllocSize) }, + New: func() any { return &payload{Data: make([]byte, 0, defaultAllocSize)} }, } -func getPayload() []byte { - return putBytesPool.Get().([]byte) +func getPayload() *payload { + return putBytesPool.Get().(*payload) } -func putPayload(p []byte) { - //nolint:staticcheck - putBytesPool.Put(p[:0]) +func putPayload(p *payload) { + p.Data = p.Data[:0] + putBytesPool.Put(p) }