Open ParkMyCar opened 3 years ago
Because Strings encoded in a proto message should be UTF8, I added a feature flag zero_copy_string_no_utf8_check
, to skip utf8 validation, when using zero-copy strings. Using this flag, we get performance similar to zero copy bytes
test bench::benches::bench_deserialize_zero_copy_bytes ... bench: 98 ns/iter (+/- 4)
test bench::benches::bench_deserialize_zero_copy_string ... bench: 101 ns/iter (+/- 2)
I thought this was a pretty interesting task, adding zero copy de-serialization for Strings! Still a work in progress, but basically I created a type
StrBytes
which is a wrapper around aBytes
struct, and on creation we assert it's valid UTF-8, which it should be because based on the protobuf spec, strings are encoded in valid UTF-8.Benchmarks (2014 MacBook Pro with an i7)
Note: The reason zero copy strings are not as fast as zero copy bytes is because we do the extra validation step