Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize numeric value serialization/deserialization #109

Open
letmutx opened this issue Feb 8, 2020 · 1 comment
Open

Optimize numeric value serialization/deserialization #109

letmutx opened this issue Feb 8, 2020 · 1 comment

Comments

@letmutx
Copy link
Collaborator

letmutx commented Feb 8, 2020

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:

let s: String = FromMemcacheValue::from_memcache_value(value, 0)?;

serialization:
match stream.write_all(self.to_string().as_bytes()) {

return self.to_string().as_bytes().len();

@DefinitelyNotAnOrca
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants