Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

optimize memory allocation of changesets with many small strings #5614

Merged
merged 2 commits into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Fixed
* <How do the end-user experience this issue? what was the impact?> ([#????](https://github.com/realm/realm-core/issues/????), since v?.?.?)
* Fix a UBSan failure when mapping encrypted pages.
* Improved performance of sync clients during integration of changesets with many small strings (totalling > 1024 bytes per changeset) on iOS 14, and devices which have restrictive or fragmented memory. ([#5614](https://github.com/realm/realm-core/issues/5614))

### Breaking changes
* None.
Expand Down
7 changes: 6 additions & 1 deletion src/realm/sync/changeset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,12 @@ inline StringData Changeset::string_data() const noexcept

inline StringBufferRange Changeset::append_string(StringData string)
{
m_string_buffer->reserve(1024); // we expect more strings
// We expect more strings. Only do this at the beginning because until C++20, reserve
// will shrink_to_fit if the request is less than the current capacity.
constexpr size_t small_string_buffer_size = 1024;
if (m_string_buffer->capacity() < small_string_buffer_size) {
m_string_buffer->reserve(small_string_buffer_size);
}
size_t offset = m_string_buffer->size();
m_string_buffer->append(string.data(), string.size());
return StringBufferRange{uint32_t(offset), uint32_t(string.size())};
Expand Down