diff --git a/ecstore/src/disk/local.rs b/ecstore/src/disk/local.rs index 5b163c5bb..e13dbd549 100644 --- a/ecstore/src/disk/local.rs +++ b/ecstore/src/disk/local.rs @@ -671,12 +671,21 @@ impl LocalDisk { } }; - let data: &[u8] = match &data { - InternalBuf::Ref(buf) => buf, - InternalBuf::Owned(buf) => buf.as_ref(), - }; - - f.write_all(data).await.map_err(to_file_error)?; + match data { + InternalBuf::Ref(buf) => { + f.write_all(buf).await.map_err(to_file_error)?; + } + InternalBuf::Owned(buf) => { + // Reduce one copy by using the owned buffer directly. + // It may be more efficient for larger writes. + let mut f = f.into_std().await; + let task = tokio::task::spawn_blocking(move || { + use std::io::Write as _; + f.write_all(buf.as_ref()).map_err(to_file_error) + }); + task.await??; + } + } Ok(()) }