Skip to content

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
mapleFU
mapleFU previously approved these changes Dec 10, 2024
} 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...

@sonarqubecloud
Copy link

@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