From e78c56d2712d05bd6b9fb1ea8bb6c94b76dc315f Mon Sep 17 00:00:00 2001 From: Ed Seidl Date: Wed, 29 Oct 2025 20:44:28 -0700 Subject: [PATCH] optimization for read_vlq --- parquet/src/parquet_thrift.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/parquet/src/parquet_thrift.rs b/parquet/src/parquet_thrift.rs index 8ee018ef95db..f9fa66ee0d3f 100644 --- a/parquet/src/parquet_thrift.rs +++ b/parquet/src/parquet_thrift.rs @@ -276,8 +276,13 @@ pub(crate) trait ThriftCompactInputProtocol<'a> { /// Read a ULEB128 encoded unsigned varint from the input. fn read_vlq(&mut self) -> ThriftProtocolResult { - let mut in_progress = 0; - let mut shift = 0; + // try the happy path first + let byte = self.read_byte()?; + if byte & 0x80 == 0 { + return Ok(byte as u64); + } + let mut in_progress = (byte & 0x7f) as u64; + let mut shift = 7; loop { let byte = self.read_byte()?; in_progress |= ((byte & 0x7F) as u64).wrapping_shl(shift);