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.
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;