Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

perf(fix): Use boost vector as underlying storage for the buffer instead of the std::vector #232

Merged
merged 1 commit into from
Apr 2, 2024

Conversation

art-gs
Copy link
Contributor

@art-gs art-gs commented Apr 2, 2024

Buffer::prepare() is called every time when sth is about to be written to the buffer, it includes calling of vector::resize().

It turned out that resize() is not so cheap if current capacity is more than requested size, because it touches newly requested chunk of memory.
Measurements showed that boost::vector does it a bit more efficient by using memset() while std::vector uses std::__uninitialized_default_n_a()

SDB-6760

Buffer::prepare() is called every time when sth is about to be written
to the buffer, it includes calling of vector::resize().

It turned out that resize() is not so cheap if current capacity is
more than requested size, because it touches newly requested chunk of
memory.
Measurements showed that boost::vector does it a bit more efficient
by using memset() while std::vector uses std::__uninitialized_default_n_a()

SDB-6760
@art-gs art-gs requested a review from a team as a code owner April 2, 2024 09:13
@art-gs
Copy link
Contributor Author

art-gs commented Apr 2, 2024

std vector

% re-lpfixgw-bench --filter=citi_esp
NAME                                                   COUNT       MIN       %50       %95       %99     %99.9    %99.99
------------------------------------------------------------------------------------------------------------------------
citi_esp                                              425630      5.14     5.964     8.388    10.337    45.714   766.135

boost vector

% re-lpfixgw-bench --filter=citi_esp         
NAME                                                   COUNT       MIN       %50       %95       %99     %99.9    %99.99
------------------------------------------------------------------------------------------------------------------------
citi_esp                                              445290     4.526      5.58       8.5     9.981    45.875   1281.28

Note: 99.99% percentage looks worse, it is because boost::vector has different grow factor during reallocation, i.e. it reallocates more often bit using lesser chunks. It is one time thing - buffer grows while the first message is being formatted, subsequent messages re-use the buffer.

@art-gs art-gs changed the title perf(fix): Use boost vector as buffer instead of std::vector perf(fix): Use boost vector as underlying storage for the buffer instead of std::vector Apr 2, 2024
@art-gs art-gs changed the title perf(fix): Use boost vector as underlying storage for the buffer instead of std::vector perf(fix): Use boost vector as underlying storage for the buffer instead of the std::vector Apr 2, 2024
@art-gs art-gs merged commit 4c91fbf into master Apr 2, 2024
7 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants