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

refactor: reduce memory copying during incremental synchronization #2689

Merged
merged 2 commits into from
Dec 11, 2024

Conversation

RiversJin
Copy link
Contributor

Optimized the logic for handling Psync incremental data on replica nodes, reducing an unnecessary data copy and lowering the loop complexity in the corresponding logic.

@RiversJin RiversJin changed the title Reduce memory copying during incremental synchronization refactor: reduce memory copying during incremental synchronization Dec 10, 2024
src/cluster/replication.cc Outdated Show resolved Hide resolved
mapleFU
mapleFU previously approved these changes Dec 10, 2024
src/cluster/replication.cc Outdated Show resolved Hide resolved
} else {
char* bulk_data = reinterpret_cast<char *>(evbuffer_pullup(input, static_cast<ssize_t>(incr_bulk_len_ + 2)));
std::string bulk_string = std::string(bulk_data, incr_bulk_len_);
evbuffer_drain(input, incr_bulk_len_ + 2);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to this issue directly

I'm not familiar with evbuffer api, but would

std::string bulk_string(0, incr_bulk_len_);
evbuffer_remove(input, bulk_string.data(), incr_bulk_len_ + 2);

Being ok since it avoid adjust the input internal? (The bad things is that std::string would zero-initialize itself, which introducing a round of copying 😅) @git-hulk @PragmaTwice

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh let's not optimize this if no benchmark shows it's better...

PragmaTwice
PragmaTwice previously approved these changes Dec 11, 2024
Copy link
Member

@PragmaTwice PragmaTwice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Thank you!

…ronization

Optimized the logic for handling Psync incremental data on replica nodes, reducing an unnecessary data copy and lowering the loop complexity in the corresponding logic.
@PragmaTwice
Copy link
Member

PragmaTwice commented Dec 11, 2024

You can run ./x.py format from the root dir of the repo to format code via clang-format.

Additional, please ensure clang-format exists and is in version 14. (download from here)

Read https://kvrocks.apache.org/community/contributing for more information.

@PragmaTwice
Copy link
Member

PragmaTwice commented Dec 11, 2024

Also, although it's not mandatory, it's good to make your further changes small additional commits instead of amending to the existing commit, to make reviewers easy to know what you change after a round of reviewing.

@RiversJin
Copy link
Contributor Author

Also, although it's not mandatory, it's good to make your further changes small additional commits instead of amending to the existing commit, to make reviewers easy to know what you change after a round of reviewing.

ok, fixed. I was a bit surprised to find that different versions of clang-format can produce different results under the same configuration file...

@PragmaTwice PragmaTwice merged commit 6bbdc55 into apache:unstable Dec 11, 2024
33 checks passed
@PragmaTwice
Copy link
Member

Thank you for your contribution!

@RiversJin RiversJin deleted the refact/replication branch December 11, 2024 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants