aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2023-10-25 22:03:14 +0200
committerGitHub <[email protected]>2023-10-25 22:03:14 +0200
commit28aaf25e651d274f1c52befdedf66b9768f415e8 (patch)
treec117a285018344de06b323dca9e1fbc6f90084fa
parent0.2.29-pre0 (diff)
downloadzen-28aaf25e651d274f1c52befdedf66b9768f415e8.tar.xz
zen-28aaf25e651d274f1c52befdedf66b9768f415e8.zip
only measure a variable integer once where we can (#500)
-rw-r--r--CHANGELOG.md1
-rw-r--r--src/zencore/compactbinary.cpp4
-rw-r--r--src/zencore/include/zencore/varint.h22
3 files changed, 20 insertions, 7 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ee380ca6c..3b2d93166 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,7 @@
- Improvement: Command `zen gc-status` now gives details about storage, when last GC occured, how long until next GC etc
- Improvement: New rotating file logger that keeps on running regardless of errors to avoid spamming error reports on OOM or OOD
- Improvement: Removed HttpCidStore (was already deprecated)
+- Improvement: Optimized cases in CompactBinary reader where we would measure a variable integer twice
- Changed: Cache access and write log are disabled by default
- Changed: We no longer purge out block location for missing blocks to allow testing/analisys of snapshots of server states without copying full set of data
- Changed: Merged cache memory layer with cache disk layer to reduce memory and cpu overhead
diff --git a/src/zencore/compactbinary.cpp b/src/zencore/compactbinary.cpp
index 5b599dda3..416b49f62 100644
--- a/src/zencore/compactbinary.cpp
+++ b/src/zencore/compactbinary.cpp
@@ -1319,7 +1319,7 @@ TryMeasureCompactBinary(MemoryView View, CbFieldType& OutType, uint64_t& OutSize
return false;
}
- const uint64_t NameLen = ReadVarUInt(View.GetData(), NameLenByteCount);
+ const uint64_t NameLen = ReadMeasuredVarUInt(View.GetData(), NameLenByteCount);
const uint64_t NameSize = NameLen + NameLenByteCount;
if (bDynamicSize && View.GetSize() < NameSize)
@@ -1353,7 +1353,7 @@ TryMeasureCompactBinary(MemoryView View, CbFieldType& OutType, uint64_t& OutSize
OutSize = Size + PayloadSizeByteCount;
return false;
}
- const uint64_t PayloadSize = ReadVarUInt(View.GetData(), PayloadSizeByteCount);
+ const uint64_t PayloadSize = ReadMeasuredVarUInt(View.GetData(), PayloadSizeByteCount);
OutSize = Size + PayloadSize + PayloadSizeByteCount;
}
return true;
diff --git a/src/zencore/include/zencore/varint.h b/src/zencore/include/zencore/varint.h
index e57e1d497..c0d63d814 100644
--- a/src/zencore/include/zencore/varint.h
+++ b/src/zencore/include/zencore/varint.h
@@ -104,15 +104,12 @@ MeasureVarInt(int64_t InValue)
* Read a variable-length unsigned integer.
*
* @param InData A variable-length encoding of an unsigned integer.
- * @param OutByteCount The number of bytes consumed from the input.
+ * @param ByteCount The number of bytes to be consumed from the input.
* @return An unsigned integer.
*/
inline uint64_t
-ReadVarUInt(const void* InData, uint32_t& OutByteCount)
+ReadMeasuredVarUInt(const void* InData, uint32_t ByteCount)
{
- const uint32_t ByteCount = MeasureVarUInt(InData);
- OutByteCount = ByteCount;
-
const uint8_t* InBytes = static_cast<const uint8_t*>(InData);
uint64_t Value = *InBytes++ & uint8_t(0xff >> ByteCount);
switch (ByteCount - 1)
@@ -155,6 +152,21 @@ ReadVarUInt(const void* InData, uint32_t& OutByteCount)
}
/**
+ * Read a variable-length unsigned integer.
+ *
+ * @param InData A variable-length encoding of an unsigned integer.
+ * @param OutByteCount The number of bytes consumed from the input.
+ * @return An unsigned integer.
+ */
+inline uint64_t
+ReadVarUInt(const void* InData, uint32_t& OutByteCount)
+{
+ const uint32_t ByteCount = MeasureVarUInt(InData);
+ OutByteCount = ByteCount;
+ return ReadMeasuredVarUInt(InData, ByteCount);
+}
+
+/**
* Read a variable-length signed integer.
*
* @param InData A variable-length encoding of a signed integer.