From 109c371d398ee3641b6cf21703d852683d18f574 Mon Sep 17 00:00:00 2001 From: John VanEnk Date: Thu, 12 May 2022 17:06:13 -0700 Subject: [PATCH] perf: remove flush from ser::into_writer. When serializing many records into a writer, it is advantageous to batch the writes when persisting to a disk or transmitting them over a socket. The current implementation of `into_writer()` flushes the encoder after every call which, in turn, flushes the underlying writer. This commit removes the flush from the call to `into_writer()` allowing the programmer to take advantage of tools like `std::io::BufWriter`. I was concerned that the encoder could maintain some state that would be lost if it was dropped before a flush, however, I do not believe this to be the case because the `Encoder` type is a simple wrapper around a type implementing the `Write` trait, and the invocation of `flush()` is on that inner type rather than on anything in the encoder itself. Therefore call to flush cannot affect the `Encoder` in any way. Signed-off-by: John VanEnk --- ciborium/src/ser/mod.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ciborium/src/ser/mod.rs b/ciborium/src/ser/mod.rs index 0488d72..ff3d118 100644 --- a/ciborium/src/ser/mod.rs +++ b/ciborium/src/ser/mod.rs @@ -495,6 +495,5 @@ where W::Error: core::fmt::Debug, { let mut encoder = Serializer::from(writer); - value.serialize(&mut encoder)?; - Ok(encoder.0.flush()?) + value.serialize(&mut encoder) }