-
Type:
Task
-
Resolution: Fixed
-
Priority:
Major - P3
-
Affects Version/s: None
-
Component/s: Performance
-
None
-
Query Execution
-
Fully Compatible
-
QE 2026-03-02
-
None
-
None
-
None
-
None
-
None
-
None
-
None
This PR changes the internal implementation of `hexblob::encode(...)` and `hexblob::decode(...)` to use more efficient building blocks. It also adds a micro benchmark.
Results on this branch, when using the changes from this PR:
```
Running bazel-bin/src/mongo/util/hex_bm
Run on (8 X 243.75 MHz CPU s)
CPU Caches:
L1 Data 64 KiB (x8)
L1 Instruction 64 KiB (x8)
L2 Unified 1024 KiB (x8)
L3 Unified 32768 KiB (x1)
Load Average: 2.44, 0.78, 0.76
------------------------------------------------------------------------------
Benchmark Time CPU Iterations UserCounters...
------------------------------------------------------------------------------
BM_HexEncode/0 6.52 ns 6.52 ns 105905480 CumulativeSizeOfEncodedStrings=0
BM_HexEncode/8 58.1 ns 58.1 ns 12043618 CumulativeSizeOfEncodedStrings=192.698M
BM_HexEncode/16 71.3 ns 71.3 ns 9800382 CumulativeSizeOfEncodedStrings=313.612M
BM_HexEncode/128 245 ns 245 ns 2852292 CumulativeSizeOfEncodedStrings=730.187M
BM_HexEncode/1024 1638 ns 1638 ns 427274 CumulativeSizeOfEncodedStrings=875.057M
BM_HexEncode/16384 25387 ns 25372 ns 27595 CumulativeSizeOfEncodedStrings=904.233M
BM_HexEncode/131072 206996 ns 206990 ns 3380 CumulativeSizeOfEncodedStrings=886.047M
BM_HexDecode/0 7.61 ns 7.61 ns 91964148 CumulativeSizeOfDecodedStrings=0
BM_HexDecode/8 21.2 ns 21.2 ns 32960137 CumulativeSizeOfDecodedStrings=131.841M
BM_HexDecode/16 30.1 ns 30.1 ns 23291391 CumulativeSizeOfDecodedStrings=186.331M
BM_HexDecode/128 202 ns 200 ns 3524856 CumulativeSizeOfDecodedStrings=225.591M
BM_HexDecode/1024 1249 ns 1249 ns 561399 CumulativeSizeOfDecodedStrings=287.436M
BM_HexDecode/16384 19080 ns 19080 ns 36393 CumulativeSizeOfDecodedStrings=298.131M
BM_HexDecode/131072 152725 ns 152721 ns 4600 CumulativeSizeOfDecodedStrings=301.466M
```
Results when using current master, without the changes from this PR:
```
------------------------------------------------------------------------------
Benchmark Time CPU Iterations UserCounters...
------------------------------------------------------------------------------
BM_HexEncode/0 10.7 ns 10.7 ns 65883537 CumulativeSizeOfEncodedStrings=0
BM_HexEncode/8 83.2 ns 83.2 ns 8409677 CumulativeSizeOfEncodedStrings=134.555M
BM_HexEncode/16 125 ns 125 ns 5622973 CumulativeSizeOfEncodedStrings=179.935M
BM_HexEncode/128 695 ns 695 ns 1006284 CumulativeSizeOfEncodedStrings=257.609M
BM_HexEncode/1024 5264 ns 5264 ns 132748 CumulativeSizeOfEncodedStrings=271.868M
BM_HexEncode/16384 83663 ns 83657 ns 8365 CumulativeSizeOfEncodedStrings=274.104M
BM_HexEncode/131072 671577 ns 671519 ns 1045 CumulativeSizeOfEncodedStrings=273.94M
BM_HexDecode/0 11.2 ns 11.2 ns 62390107 CumulativeSizeOfDecodedStrings=0
BM_HexDecode/8 37.3 ns 37.3 ns 18722921 CumulativeSizeOfDecodedStrings=74.8917M
BM_HexDecode/16 63.4 ns 63.4 ns 11041350 CumulativeSizeOfDecodedStrings=88.3308M
BM_HexDecode/128 426 ns 426 ns 1632322 CumulativeSizeOfDecodedStrings=104.469M
BM_HexDecode/1024 3075 ns 3075 ns 227603 CumulativeSizeOfDecodedStrings=116.533M
BM_HexDecode/16384 48480 ns 48480 ns 14436 CumulativeSizeOfDecodedStrings=118.26M
BM_HexDecode/131072 388982 ns 388979 ns 1800 CumulativeSizeOfDecodedStrings=117.965M
```
Diff:
```
Comparing /home/ubuntu/mongo-dev/mongo/master_bm to /home/ubuntu/mongo-dev/mongo/branch_bm
Benchmark Time CPU Time Old Time New CPU Old CPU New
------------------------------------------------------------------------------------------------------------------
BM_HexEncode/0 -0.4055 -0.4055 11 6 11 6
BM_HexEncode/8 -0.2981 -0.2981 83 58 83 58
BM_HexEncode/16 -0.4296 -0.4286 125 71 125 71
BM_HexEncode/128 -0.6352 -0.6352 695 253 695 253
BM_HexEncode/1024 -0.6768 -0.6768 5262 1701 5262 1700
BM_HexEncode/16384 -0.6845 -0.6845 83631 26382 83629 26382
BM_HexEncode/131072 -0.6790 -0.6790 669928 215019 669907 215016
BM_HexDecode/0 -0.3520 -0.3520 11 7 11 7
BM_HexDecode/8 -0.4316 -0.4317 37 21 37 21
BM_HexDecode/16 -0.5249 -0.5249 63 30 63 30
BM_HexDecode/128 -0.5326 -0.5326 426 199 426 199
BM_HexDecode/1024 -0.5977 -0.5977 3075 1237 3075 1237
BM_HexDecode/16384 -0.6071 -0.6071 48490 19050 48489 19049
BM_HexDecode/131072 -0.6090 -0.6090 389080 152147 389070 152144
OVERALL_GEOMEAN -0.5491 -0.5490 0 0 0 0
```