-
Notifications
You must be signed in to change notification settings - Fork 622
Closed
Labels
Description
It currently looks like this:
fn serialize_u64(&mut self, value: u64) -> Result<()> {
write!(&mut self.writer, "{}", value).map_err(From::from)
}I tested the following variation and it made an astonishing 20% difference in the bench_log benchmarks (294 MB/s vs 244 MB/s).
if value == 0 {
self.writer.write_all(b"0").map_err(From::from)
} else {
let mut scratch = [0u8; 20];
let mut len = 0;
while value > 0 {
scratch[19 - len] = (value % 10) as u8 + b'0';
value /= 10;
len += 1;
}
self.writer.write_all(&scratch[20-len..20]).map_err(From::from)
}That is enough to motivate looking for a better solution, or contributing a fix to Rust for whatever is making write! slow.
StefanoD and maciejhirsz