]> git.ipfire.org Git - thirdparty/squid.git/commit
Optimization: Avoid more SBuf::cow() reallocations (#744)
authorAlex Rousskov <rousskov@measurement-factory.com>
Wed, 4 Nov 2020 14:27:22 +0000 (14:27 +0000)
committerAmos Jeffries <yadij@users.noreply.github.com>
Tue, 17 Nov 2020 01:10:07 +0000 (14:10 +1300)
commit1dfbca0695bd9b5fd97ac123a070ca2bfe52d9dc
treee1766c06598109cb120159572e73a196748e53c6
parent425de816d150878981efca2352f818d973e4ba4e
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