p2p: Serialize cmpctblock at most once in NewPoWValidBlock#23880
p2p: Serialize cmpctblock at most once in NewPoWValidBlock#23880maflcko merged 1 commit intobitcoin:masterfrom
Conversation
|
Concept ACK IIRC I also tried to tackle this TODO some time ago but failed as move-semantics prevented to store the serialized message. This PR is now a good opportunity to learn about futures and |
|
Yeah, it is not possible to unconditionally |
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
shaavan
left a comment
There was a problem hiding this comment.
ACK fabe7843a767505abdc580581e330fb4f963c788
I was researching about this PR. I found this useful article. It talks about how using std::deferred allows lazy calculations. If the value has been already calculated, it will not be recalculated, potentially decreasing the number of times serialization is done to one.
I have reviewed the code changes in this PR, and I found them agreeable.
fabe784 to
fa61dd4
Compare
There was a problem hiding this comment.
After doing some more research about the concepts of futures and lazy evaluation in C++, I'm convinced now that this change is correct. This seems to be the first time ever that std::async and std::shared_future are used in the Bitcoin Core codebase.
Code-review ACK fa61dd4
…ValidBlock fa61dd4 p2p: Serialize cmpctblock at most once in NewPoWValidBlock (MarcoFalke) Pull request description: Instead of serializing for each peer, serialize at most once and copy the raw data for each peer. ACKs for top commit: shaavan: reACK fa61dd4 theStack: Code-review ACK fa61dd4 Tree-SHA512: ed029aeaea67fdac8ddb865069f8166bc0dd8480418c405628e3e1a43b61161584a09a1814668bcd220602e8732e188be2bfed9242aa81bdbd92c64c702ed138
|
Concept ACK. Is there a reason you need a - const std::shared_future<CSerializedNetMsg> lazy_ser{
+ std::future<CSerializedNetMsg> lazy_ser{Could the same future be used to replace the |
|
No, that'd be UB, see https://en.cppreference.com/w/cpp/thread/future/get
|
Likely, but I haven't checked. |
Ah! Thanks. |
|
For reference, for anyone wondering: A copy from the lazy ser is 25% faster on my machine than serialize. |
Instead of serializing for each peer, serialize at most once and copy the raw data for each peer.