diff options
| author | Dan Engelbrecht <[email protected]> | 2026-02-06 12:43:26 +0100 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2026-02-06 12:43:26 +0100 |
| commit | eabf78d92a560f2480b0ca4409069be08e1e1f15 (patch) | |
| tree | 04a915e8326c12897a73d84b7814a4d68a925d61 | |
| parent | fix target folder cleanup in builds download (#746) (diff) | |
| download | zen-eabf78d92a560f2480b0ca4409069be08e1e1f15.tar.xz zen-eabf78d92a560f2480b0ca4409069be08e1e1f15.zip | |
ported optimizations of MeasureVarUInt (#747)
| -rw-r--r-- | CHANGELOG.md | 1 | ||||
| -rw-r--r-- | src/zencore/include/zencore/varint.h | 14 |
2 files changed, 13 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 41cc5349d..cd4e9781a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - Improvement: Increased the default scrub timeslice from 1 min 40 sec to 5 min. - Improvement: Reduce lock contention when performing a scrub operation - Improvement: Replaced http routing regex matching with faster matching lambdas for admin, buildstore, projectstore, objectstore and workspaces services +- Improvement: Ported optimizations of MeasureVarUInt from UE (CL50464402) - Bugfix: Restore `/health/log` and `/health/info` endpoint functionality - Bugfix: Fixed 32-bit truncation of transmission chunk sizes when using the asio http path - Bugfix: `zen builds download` could leave files from previous downloads in the target folder diff --git a/src/zencore/include/zencore/varint.h b/src/zencore/include/zencore/varint.h index ae9aceed6..9fe905f25 100644 --- a/src/zencore/include/zencore/varint.h +++ b/src/zencore/include/zencore/varint.h @@ -76,14 +76,24 @@ MeasureVarInt(const void* InData) inline uint32_t MeasureVarUInt(uint32_t InValue) { - return uint32_t(int32_t(FloorLog2(InValue)) / 7 + 1); + // return + // This branching implementation is faster than branchless alternatives in real-world benchmarks. + // Replaces: uint32_t(int32_t(FloorLog2(InValue)) / 7 + 1); + return (InValue < (uint32_t(1) << 28)) + ? ((InValue < (uint32_t(1) << 14)) ? ((InValue < (uint32_t(1) << 7)) ? 1 : 2) : ((InValue < (uint32_t(1) << 21)) ? 3 : 4)) + : 5; } /** Measure the number of bytes (1-9) required to encode the 64-bit input. */ inline uint32_t MeasureVarUInt(uint64_t InValue) { - return uint32_t(std::min(int32_t(FloorLog2_64(InValue)) / 7 + 1, 9)); + // This branching implementation is faster than branchless alternatives in real-world benchmarks. + // Replaces: uint32_t(std::min(int32_t(FloorLog2_64(InValue)) / 7 + 1, 9)); + return (InValue < (uint64_t(1) << 28)) + ? ((InValue < (uint64_t(1) << 14)) ? ((InValue < (uint64_t(1) << 7)) ? 1 : 2) : ((InValue < (uint64_t(1) << 21)) ? 3 : 4)) + : ((InValue < (uint64_t(1) << 42)) ? ((InValue < (uint64_t(1) << 35)) ? 5 : 6) + : ((InValue < (uint64_t(1) << 49)) ? 7 : ((InValue < (uint64_t(1) << 56)) ? 8 : 9))); } /** Measure the number of bytes (1-5) required to encode the 32-bit input. \see \ref MeasureVarUInt */ |