-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[Issue 13285][pulsar-client] Optimize MessageBuilder and SharedBuffer to avoid unnecessary memory copy. #13293
Conversation
… to avoid unnecessary memory copy.
@tongsucn:Thanks for your contribution. For this PR, do we need to update docs? |
@tongsucn:Thanks for providing doc info! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tongsucn Can you also add a unit tests for the new setContent()
method?
I have a suggestion for testing the memory copy doesn't occur after this change, but it might depend on the implementation of TEST(MessageBuilderTest, testSetContent) {
std::string value;
value.resize(1024, 'x');
const void* originalAddress = &value[0];
{
auto msg = MessageBuilder().setContent(value).build();
ASSERT_NE(msg.getData(), originalAddress);
}
{
auto msg = MessageBuilder().setContent(std::move(value)).build();
ASSERT_EQ(msg.getData(), originalAddress);
}
} |
@BewareMyPower I think the first |
@tongsucn Any update on this PR? |
@codelipenghui Just added a test case on |
@tongsucn You should either rebase or merge with master as there were some merge conflicts that make the checkstyle to fail. It's already fixed in latest master. |
… to avoid unnecessary memory copy. (apache#13293) * [Issue 13285][pulsar-client] Optimize MessageBuilder and SharedBuffer to avoid unnecessary memory copy. * [Issue 13285][pulsar-client] Fixed an error in move-assigment-operator. * [Issue 13285][pulsar-client] Added new test case for MessageBuilder::setContent. * [Issue 13285][pulsar-client] Fixed bug in test case. * [Issue 13285][pulsar-client] Fixed bug in test case.
Fixes #13285
Motivation
See more in #13285
Modifications
std::vector<char>
withstd::string
as the internal storage ofSharedBuffer
.MessageBuilder::setContent(std::string&&)
.SharedBuffer
.Does this pull request potentially affect one of the following parts:
Documentation
Check the box below and label this PR (if you have committer privilege).
Need to update docs?
no-need-doc
It does not add any new public interface, the comment on the function declaration is enough.