BewareMyPower opened a new issue, #306:
URL: https://github.com/apache/pulsar-client-cpp/issues/306

   ### Search before asking
   
   - [X] I searched in the 
[issues](https://github.com/apache/pulsar-client-cpp/issues) and found nothing 
similar.
   
   ### Version
   
   3.3.0
   
   ### Minimal reproduce step
   
   Modify the `OpSendMsg` to:
   
   ```c++
       OpSendMsg() { std::cout << "OpSendMsg(): " << sizeof(metadata_) << " 
bytes\n"; }
       OpSendMsg(const proto::MessageMetadata& metadata, const SharedBuffer& 
payload,
                 const SendCallback& sendCallback, uint64_t producerId, 
uint64_t sequenceId, int sendTimeoutMs,
                 uint32_t messagesCount, uint64_t messagesSize, 
ChunkMessageIdImplPtr chunkedMessageId = nullptr)
           : metadata_(metadata),  // the copy happens here because OpSendMsg 
of chunks are constructed with
                                   // a shared metadata object
             payload_(payload),
             sendCallback_(sendCallback),
             producerId_(producerId),
             sequenceId_(sequenceId),
             timeout_(TimeUtils::now() + milliseconds(sendTimeoutMs)),
             messagesCount_(messagesCount),
             messagesSize_(messagesSize),
             chunkedMessageId_(chunkedMessageId) {
           std::cout << "OpSendMsg metadata: " << sizeof(metadata_) << " bytes" 
<< std::endl;
       }
   
       OpSendMsg(const OpSendMsg& rhs)
           : metadata_(rhs.metadata_),
             payload_(rhs.payload_),
             sendCallback_(rhs.sendCallback_),
             producerId_(rhs.producerId_),
             sequenceId_(rhs.sequenceId_),
             timeout_(rhs.timeout_),
             messagesCount_(rhs.messagesCount_),
             messagesSize_(rhs.messagesSize_),
             trackerCallbacks_(rhs.trackerCallbacks_),
             chunkedMessageId_(rhs.chunkedMessageId_) {
           std::cout << "OpSendMsg copy" << std::endl;
       }
   ```
   
   Modify the `example/SampleProducer.cc` to:
   
   ```c++
       Producer producer;
       ProducerConfiguration conf;
       conf.setBatchingMaxMessages(5);
       Result result = 
client.createProducer("persistent://public/default/my-topic", conf, producer);
       if (result != ResultOk) {
           LOG_ERROR("Error creating producer: " << result);
           return -1;
       }
   
       for (int i = 0; i < 100; i++) {
           Message msg = MessageBuilder().setContent("content").build();
           producer.sendAsync(msg, {});
       }
   
       std::this_thread::sleep_for(std::chrono::seconds(1));
   ```
   
   Then, run the `SampleProducer`.
   
   ### What did you expect to see?
   
   No copy happened.
   
   ### What did you see instead?
   
   ```
   OpSendMsg(): 248 bytes
   OpSendMsg copy
   OpSendMsg(): 248 bytes
   OpSendMsg copy
   OpSendMsg(): 248 bytes
   OpSendMsg copy
   OpSendMsg(): 248 bytes
   OpSendMsg copy
   OpSendMsg(): 248 bytes
   OpSendMsg copy
   OpSendMsg(): 248 bytes
   OpSendMsg copy
   OpSendMsg copy
   OpSendMsg(): 248 bytes
   OpSendMsg copy
   OpSendMsg copy
   OpSendMsg(): 248 bytes
   OpSendMsg copy
   OpSendMsg(): 248 bytes
   OpSendMsg copy
   OpSendMsg copy
   OpSendMsg copy
   OpSendMsg(): 248 bytes
   OpSendMsg copy
   OpSendMsg(): 248 bytes
   OpSendMsg copy
   OpSendMsg(): 248 bytes
   OpSendMsg copy
   OpSendMsg copy
   OpSendMsg copy
   OpSendMsg(): 248 bytes
   OpSendMsg copy
   OpSendMsg copy
   OpSendMsg(): 248 bytes
   OpSendMsg copy
   OpSendMsg copy
   OpSendMsg(): 248 bytes
   OpSendMsg copy
   OpSendMsg(): 248 bytes
   OpSendMsg copy
   OpSendMsg(): 248 bytes
   OpSendMsg copy
   OpSendMsg(): 248 bytes
   OpSendMsg copy
   OpSendMsg(): 248 bytes
   OpSendMsg copy
   OpSendMsg(): 248 bytes
   OpSendMsg copy
   ```
   
   The copy constructor of `OpSendMsg` has been called many times. Since the 
size of `MessageMetadata` is 248 bytes, the copy overhead is high. We should 
avoid copying `OpSendMsg`.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to