rust-memcache icon indicating copy to clipboard operation
rust-memcache copied to clipboard

Optimize numeric value serialization/deserialization

Open letmutx opened this issue 4 years ago • 1 comments

We call num.to_string().as_bytes() to serialize and deserialize numbers when setting them in memcache server. Instead, we could use byteorder crate's read_u16, read_u64 etc. and write out the bytes to the server with a specific endianness(big/little) and use the same when deserializing. deserialization: https://github.com/aisk/rust-memcache/blob/faed4e117b8108dbcae1901c891844009229190e/src/value.rs#L161 serialization: https://github.com/aisk/rust-memcache/blob/faed4e117b8108dbcae1901c891844009229190e/src/value.rs#L95 https://github.com/aisk/rust-memcache/blob/faed4e117b8108dbcae1901c891844009229190e/src/value.rs#L91

letmutx avatar Feb 08 '20 16:02 letmutx

I have been doing some digging on this, and I am not sure if this is the best idea. Specifically because if we did use the byteorder read functions, the memcached commands incr and decr would automatically fail because the read bytes are not the string representation of the number that is being stored (Source: https://github.com/memcached/memcached/wiki/Commands#incrdecr). This is fine on the numbers that cannot be represented within a u64, but I question if it is worth this small optimization, especially because it will have different performance behaviors depending on if a number is positive or negative.

DefinitelyNotAnOrca avatar May 10 '23 22:05 DefinitelyNotAnOrca