]> git.kaiwu.me - haproxy.git/commit
OPTIM: log/tools: switch from function pointer design to dual mode HEX/BIN design...
authorAurelien DARRAGON <adarragon@haproxy.com>
Fri, 21 Aug 2026 13:34:54 +0000 (15:34 +0200)
committerAurelien DARRAGON <adarragon@haproxy.com>
Fri, 21 Aug 2026 15:54:46 +0000 (17:54 +0200)
commitc1abbb11fab79d44fb03c9e3044e50fb423e4e0a
tree8d40b485a35a32946add50e129a50392765c4698
parent03bde20ef72d40f7fd546f0725da0f787934ac1b
OPTIM: log/tools: switch from function pointer design to dual mode HEX/BIN design for CBOR encoding

Time has shown that only the HEX/BIN mode for cbor encoding were relevant
so far. And the current design based on function pointers was proved
to be a lot CPU consuming, reducing logging performances by a significant
amount (even when binary CBOR was used) compared to logs without encoding.

In order to try to recover as much logging performance as possible,
especially for the CBOR binary encoder, let's switch to a simpler design
where all cbor encoding functions are proposed in 2 distincts variants:
one for binary encoding, and the other for hex (ie: ascii compatible)
encoding. The cost of that is a code that contains a little bit of
duplication, although this was limited thanks to the use of static
inline helpers where possible to group common code. The benefit is that
no function pointers are used anymore during the encoding chain, making
the branches more predictable for CPU predictions and compiler
optimizations. To further improve the performance in CBOR binary mode
a special case was performed in cbor_encode_uint64_prefix_bin():
as suggested by Willy, for x86_64 systems we can actually directly
write int64 using memcpy() since bits are already in the correct order.
include/haproxy/tools-t.h
include/haproxy/tools.h
src/log.c
src/tools.c