Skip to content

Commit 109c371

Browse files
sw17chenarxbot
authored andcommitted
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 <[email protected]>
1 parent 234dea6 commit 109c371

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

ciborium/src/ser/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,5 @@ where
495495
W::Error: core::fmt::Debug,
496496
{
497497
let mut encoder = Serializer::from(writer);
498-
value.serialize(&mut encoder)?;
499-
Ok(encoder.0.flush()?)
498+
value.serialize(&mut encoder)
500499
}

0 commit comments

Comments
 (0)