This is an automated email from the ASF dual-hosted git repository. alexey pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/kudu.git
commit 7f7d425eadc10886108a00ee0249d7c3d8372ee0 Author: Todd Lipcon <[email protected]> AuthorDate: Tue Jun 18 00:17:04 2019 -0700 KUDU-2867. Optimize delta timestamp decoding When using hybrid clock, all timestamps require a full 8-byte varint to be encoded. So, we can inline this fast path in Timestamp::DecodeFrom to avoid the more complicated/lengthy GetMemcmpableVarint code. Change-Id: I1665e0aaed874cf4d47ecf5e467246a9505b0bd1 Reviewed-on: http://gerrit.cloudera.org:8080/13667 Tested-by: Kudu Jenkins Reviewed-by: Grant Henke <[email protected]> Reviewed-by: Alexey Serbin <[email protected]> --- src/kudu/common/timestamp.cc | 5 ----- src/kudu/common/timestamp.h | 21 ++++++++++++++++++++- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/kudu/common/timestamp.cc b/src/kudu/common/timestamp.cc index 1d13d4f..1eed806 100644 --- a/src/kudu/common/timestamp.cc +++ b/src/kudu/common/timestamp.cc @@ -21,7 +21,6 @@ #include "kudu/gutil/mathlimits.h" #include "kudu/gutil/strings/substitute.h" -#include "kudu/util/memcmpable_varint.h" namespace kudu { @@ -30,10 +29,6 @@ const Timestamp Timestamp::kMax(MathLimits<Timestamp::val_type>::kMax); const Timestamp Timestamp::kInitialTimestamp(MathLimits<Timestamp::val_type>::kMin + 1); const Timestamp Timestamp::kInvalidTimestamp(MathLimits<Timestamp::val_type>::kMax - 1); -bool Timestamp::DecodeFrom(Slice* input) { - return GetMemcmpableVarint64(input, &v); -} - void Timestamp::EncodeTo(faststring* dst) const { PutMemcmpableVarint64(dst, v); } diff --git a/src/kudu/common/timestamp.h b/src/kudu/common/timestamp.h index c9dbad7..7777b64 100644 --- a/src/kudu/common/timestamp.h +++ b/src/kudu/common/timestamp.h @@ -22,9 +22,13 @@ #include <iosfwd> #include <string> +#include "kudu/gutil/endian.h" +#include "kudu/gutil/port.h" +#include "kudu/util/memcmpable_varint.h" +#include "kudu/util/slice.h" + namespace kudu { class faststring; -class Slice; // A transaction timestamp generated by a Clock. class Timestamp { @@ -84,6 +88,21 @@ class Timestamp { std::ostream& operator<<(std::ostream& o, const Timestamp& timestamp); +inline bool Timestamp::DecodeFrom(Slice* input) { + // The most common case is that the timestamp is generated from a + // HybridClock, which will always be encoded as an 8-byte varint. + // Given this, we can inline fast-path this encoding here and fall + // back to GetMemcmpableVarint64 only in the rare case of logical + // clocks used in tests. + if (PREDICT_TRUE(input->size() >= 9 && + (*input)[0] == 0xff)) { + v = BigEndian::Load64(input->data() + 1); + input->remove_prefix(9); + return true; + } + return GetMemcmpableVarint64(input, &v); +} + inline int Timestamp::CompareTo(const Timestamp& other) const { if (v < other.v) { return -1;
