Skip to content

Commit e19d443

Browse files
committed
Skipping UTF-8 validation for map keys
Implemented in to read map keys as raw bytes (via ). This avoids redundant UTF-8 validation when serde matches field names to map keys. Benchmarks show a significant performance improvement for full record deserialization on production databases.
1 parent f7dcb5f commit e19d443

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/decoder.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,10 +602,23 @@ impl<'de: 'a, 'a> de::Deserializer<'de> for &'a mut Decoder<'de> {
602602
visitor.visit_enum(EnumAccessor { de: self })
603603
}
604604

605+
fn deserialize_identifier<V>(self, visitor: V) -> DecodeResult<V::Value>
606+
where
607+
V: Visitor<'de>,
608+
{
609+
let (_, type_num) = self.peek_type()?;
610+
if type_num == TYPE_STRING {
611+
let bytes = self.read_str_as_bytes()?;
612+
visitor.visit_borrowed_bytes(bytes)
613+
} else {
614+
self.decode_any(visitor)
615+
}
616+
}
617+
605618
forward_to_deserialize_any! {
606619
bool i8 i16 i32 i64 i128 u8 u16 u32 u64 u128 f32 f64 char str string
607620
bytes byte_buf unit unit_struct newtype_struct seq tuple
608-
tuple_struct map struct identifier
621+
tuple_struct map struct
609622
}
610623
}
611624

0 commit comments

Comments
 (0)