From: Willy Tarreau Date: Tue, 24 Nov 2026 08:46:37 +0000 (+0000) Subject: OPTIM: h1: use memcpy_opt_small() to copy chunks in the contiguous parser X-Git-Url: https://git.kaiwu.me/web/%22data:,/doc/static/%7B@url%7D?a=commitdiff_plain;h=98f0f7aff928cb365968fc97c11773170d792dfc;p=haproxy.git 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. --- diff --git a/src/h1_htx.c b/src/h1_htx.c index f3364c18c..7d85bf0cf 100644 --- a/src/h1_htx.c +++ b/src/h1_htx.c @@ -807,7 +807,7 @@ static size_t h1_parse_full_contig_chunks(struct h1m *h1m, struct htx **dsthtx, goto end_parsing; } - memcpy(dptr + dpos, end + ridx, chksz); + memcpy_opt_small(dptr + dpos, end + ridx, chksz); h1m->body_len += chksz; lmax -= chksz; dpos += chksz;