]> git.ipfire.org Git - thirdparty/squid.git/commit - src/sbuf/MemBlob.h
Optimization: Avoid more SBuf::cow() reallocations (#744)
authorAlex Rousskov <rousskov@measurement-factory.com>
Wed, 4 Nov 2020 14:27:22 +0000 (14:27 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Thu, 5 Nov 2020 17:08:17 +0000 (17:08 +0000)
commit963caaa7f4b56e31065f02e10526a8ecbfad4123
treef11f91c9da04efce0720f2d475ed5fea9d85e54c
parent47e8b5434d8832b99accbb7337d7964b7cf51d27
Optimization: Avoid more SBuf::cow() reallocations (#744)

This optimization contains two parts:

1. A no-brainer part that allows SBuf to reuse MemBlob area previously
   used by other SBufs sharing the same MemBlob. To see this change,
   follow the "cowAvoided" code path modifications in SBuf::cow().

2. A part based on a rule of thumb: memmove is usually better than
   malloc+memcpy. This part of the optimization (follow the "cowShift"
   path) is only activated if somebody has consume()d from the buffer
   earlier. The implementation is based on the heuristic that most
   consuming callers follow the usual append-consume-append-... usage
   pattern and want to preserve their buffer capacity.

MemBlob::consume() API mimics SBuf::consume() and std::string::erase(),
ignoring excessive number of bytes rather than throwing an error.

Also detailed an old difference between an SBuf::cow() requiring just a
new buffer allocation and the one also requiring data copying.

Co-Authored-By: Christos Tsantilas <christos@chtsanti.net>
src/sbuf/MemBlob.cc
src/sbuf/MemBlob.h
src/sbuf/SBuf.cc
src/sbuf/Stats.cc
src/sbuf/Stats.h
src/tests/testSBuf.cc