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
Noticed this when I was investigating this TODO item. The current serialization mechanism (serialize a two-element tuple i.e. (type, value)) seems to introduced a significant amount of overheads on the String type Values.
Unsure if it was caused by the padding, or by the serializations. But I think it's worth a further investigation.
Alternatively, we can just write the Type and Value directly to a buffer, then pass the result to put function. For big Values, we can avoid the double allocation by leveraging the "MDB_RESERVE" feature, which basically reserves enough space for the value, and return the buffer so that the user can populate the buffer afterwards. The following snippets illustrate the basic idea,
fn put(&self, key, value) {
// say BIG_VALUE_THRESHOLD = 32
let length = ::std::mem::size_of_value(&value) + 1; // value size + type size
if length < BIG_VALUE_THRESHOLD {
let buf = [u8, BIG_VALIE_THRESHOLD];
buf.write_u8(&type);
buf.write_all(&value);
self.txn.put(&k, &buf[..length]);
} else {
let mut reserved_buf = self.txn.reserve(&k, length);
reserved_buf.write_u8(&type);
reserved_buf.write_all(&value);
}
}
The text was updated successfully, but these errors were encountered:
Strings have to serialize their length. The length is stored as a 64-bit integer, therefore the additional 8 bytes.
👍
Also see #109 which would mean the user is responsible for any serialization/deserialization.
Agreed, this overhead could be undesired if the consumer only wants to store some binary blobs. Even for string values, particularly short ones, that 8 bytes overhead can make the map size estimation trickier for the consumers.
Noticed this when I was investigating this TODO item. The current serialization mechanism (serialize a two-element tuple i.e.
(type, value)
) seems to introduced a significant amount of overheads on the String typeValue
s.Here is some examples:
Unsure if it was caused by the padding, or by the serializations. But I think it's worth a further investigation.
Alternatively, we can just write the
Type
andValue
directly to a buffer, then pass the result toput
function. For bigValue
s, we can avoid the double allocation by leveraging the "MDB_RESERVE" feature, which basically reserves enough space for the value, and return the buffer so that the user can populate the buffer afterwards. The following snippets illustrate the basic idea,The text was updated successfully, but these errors were encountered: