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
MB-59746 [2/2]: Optimise space needed to store locked_CAS
Optimise the representation of the 'cas' and 'locked_cas' fields, so
they always consume 8B in StoredValue, at the cost of some complexity.
We need to store one CAS value when the SV is unlocked (common), and
two CAS values when locked (rare). We want to dto this without having
to unncessarily inflate the size of _all_ StoredValue objects, which
the current basic impl does (by always storing both cas and
locked_cas).
Logically what we want is a the 'cas' member to be variant which is
either one or two CAS values:
std::variant<uint64_t, CasPair>
However this has sizeof(max_sizeof(T...)) + 1 = 17Bytes on 64bit
systems.
To achive this funcionality using only 8B, we use two optimisations:
1. Use an external variable (casIsSeparate) as the tag of the variant
(saves 1 Byte).
2. For the CasPair variant, allocate the CasPair on the heap and just
store a ptr to it in the variant (save 8 Bytes).
(1) Somewhat complicates the code, as we need to manage the tag
manually - but that's the price we pay for avoiding the extra byte
std::variant would have..
(2) comes at the cost of an additional 16B heap allocation for locked
documents (in addition to the fixed 8B footprint of this field), but
given locked documents are very rare compared to unlocked ones, this
should overall be cheaper than spending 16B on every SV.
Change-Id: I8b95a743ef041af3d5566d13087c60213811e359
Reviewed-on: https://review.couchbase.org/c/kv_engine/+/201511
Reviewed-by: Vesko Karaganev <[email protected]>
Tested-by: Dave Rigby <[email protected]>
Well-Formed: Restriction Checker
0 commit comments