You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, doubles are "packed" into int64s by doing 3 things:
typecast the double's bytes to an int64
mask out most of the mantissa
bitshifting away all of the 0s that we just masked out
This turns the double into a fairly small int64 (IIUC, we care about "small" because it takes advantage of Protobuf's varint encoding).
Here's another approach, which might be preferable:
convert the double to a float
mask out most of the mantissa
The main differences between the two approaches are:
Range of values expressible.float has only 8 exponent bits, not 11, so it can only represent values in the range 2^(±128) instead of 2^(±1024). This seems inconsequential.
Size of representation.floats take 4 bytes; varints take less, usually, but in practice, all reasonably-sized doubles (other than exactly 0) pack to ints between 2^14 and 2^21, and therefore take 3 bytes (demo). So using floats instead would only make most bucket keys 33% larger.
Simplicity. Storing data in its natural datatype is good. The type makes it clear what's being stored, and the strings produced by languages' built-in stringification methods aren't opaque.
The text was updated successfully, but these errors were encountered:
Currently,
double
s are "packed" intoint64
s by doing 3 things:double
's bytes to anint64
This turns the
double
into a fairly smallint64
(IIUC, we care about "small" because it takes advantage of Protobuf's varint encoding).Here's another approach, which might be preferable:
double
to afloat
The main differences between the two approaches are:
float
has only 8 exponent bits, not 11, so it can only represent values in the range 2^(±128) instead of 2^(±1024). This seems inconsequential.float
s take 4 bytes; varints take less, usually, but in practice, all reasonably-sizeddouble
s (other than exactly 0) pack to ints between 2^14 and 2^21, and therefore take 3 bytes (demo). So using floats instead would only make most bucket keys 33% larger.The text was updated successfully, but these errors were encountered: