mirror of
https://github.com/quickwit-oss/tantivy.git
synced 2026-11-20 17:44:15 +00:00
perf: one-byte fast path for VInt::serialize
Lengths and counts written while serializing documents are almost always below 128. Writing them through a 10-byte buffer and a variable-size write_all showed up as memcpy calls (~3% of the bulk load CPU).
This commit is contained in:
@@ -191,7 +191,12 @@ impl VInt {
|
||||
}
|
||||
|
||||
impl BinarySerializable for VInt {
|
||||
#[inline]
|
||||
fn serialize<W: Write + ?Sized>(&self, writer: &mut W) -> io::Result<()> {
|
||||
// Most VInts are lengths and counts below 128: one byte, no variable-size copy.
|
||||
if self.0 < 128 {
|
||||
return writer.write_all(&[self.0 as u8 | STOP_BIT]);
|
||||
}
|
||||
let mut buffer = [0u8; 10];
|
||||
let num_bytes = self.serialize_into(&mut buffer);
|
||||
writer.write_all(&buffer[0..num_bytes])
|
||||
|
||||
Reference in New Issue
Block a user