]> git.kaiwu.me - haproxy.git/commit
OPTIM: h1: use memcpy_opt_small() to copy chunks in the contiguous parser
authorWilly Tarreau <w@1wt.eu>
Tue, 24 Nov 2026 08:46:37 +0000 (08:46 +0000)
committerWilly Tarreau <w@1wt.eu>
Tue, 24 Nov 2026 09:50:37 +0000 (10:50 +0100)
commit98f0f7aff928cb365968fc97c11773170d792dfc
tree99111be109d9810db6e9ba54cd9771bf281f3e88
parent8ee28984452ca81d8727d71b842d08e3d870082f
OPTIM: h1: use memcpy_opt_small() to copy chunks in the contiguous parser

The contiguous chunks parser copies each chunk's payload into the HTX
block using memcpy(). With tiny chunks, the call to the libc's memcpy()
for a copy of unknown size costs much more than the copy itself, about
20% of the time spent on a stream of 1-byte chunks. Let's use the new
memcpy_opt_small() instead, which copies chunks of up to 32 bytes inline.

The transferred data rates were measured for various chunk sizes
on a Zen4 CPU core at 5 GHz (256 MB block):

  chunk size    before (MB/s)  after (MB/s)        gain
  1                 1350           1594          +18.1%
  1 + ";1"          1327           1656          +24.8%
  1 + ";a=b"        1454           1776          +22.2%
  1 + ";a=\"b\""    1529           1790          +17.1%
  2                 1429           1707          +19.4%
  3                 1641           1898          +15.7%
  4                 1665           2030          +21.9%
  7                 1904           2275          +19.5%
  8                 1968           2493          +26.7%
  15                2542           2798          +10.1%
  16                2558           2776           +8.5%
  17                2554           2754           +7.8%
  24                2816           3012           +7.0%
  32                3018           3167           +4.9%
  33                3093           2993           -3.2%
  40                3073           3014           -1.9%
  100               3664           3611           -1.4%
  1000              4097           4010           -2.1%
  4096+             4100           4074           noise
  random 1..16      1314           1554          +18.3%

Chunks larger than 32 bytes lose a little because the call to memcpy()
is now after a few tests, but the gains, especially in attacks, is
significant.
src/h1_htx.c