This issue created for #15045
- Replace branching with a single indexed load from constexpr lookup table.
- Instead of reserve + push_back, one allocation sets final size immediately, avoiding repeated size updates and bounds checks.
- Raw pointer skips repeated operator[] overhead and internal index tracking.
- When
hex=false, construct the string directly, avoiding assign + return copy.
Noticed when using ldb --value_hex scan:
Before:
perf stat -e branches,branch-misses tools/ldb --value_hex scan --db=test_db | dd of=/dev/null
Performance counter stats for 'tools/ldb --value_hex scan --db=test_db':
2,983,373,019 branches:u
101,288,380 branch-misses:u # 3.40% of all branches
4.365280485 seconds time elapsed
2.854659000 seconds user
0.741348000 seconds sys
884520+1 records in
884520+1 records out
452874563 bytes (453 MB, 432 MiB) copied, 4.40603 s, 103 MB/s
After:
perf stat -e branches,branch-misses tools/ldb --value_hex scan --db=test_db | dd of=/dev/null
Performance counter stats for 'tools/ldb --value_hex scan --db=test_db':
275,719,553 branches:u
797,887 branch-misses:u # 0.29% of all branches
1.922297831 seconds time elapsed
0.346486000 seconds user
0.785366000 seconds sys
884520+1 records in
884520+1 records out
452874563 bytes (453 MB, 432 MiB) copied, 1.97187 s, 230 MB/s
Built with DEBUG_LEVEL=0. gcc 8.5.0
Also see #15072 Speed up Slice::DecodeHex and #15070
This issue created for #15045
hex=false, construct the string directly, avoiding assign + return copy.Noticed when using
ldb --value_hex scan:Before:
After:
Built with
DEBUG_LEVEL=0.gcc 8.5.0Also see #15072 Speed up Slice::DecodeHex and #15070