-
Notifications
You must be signed in to change notification settings - Fork 38.6k
p2p: Serialize cmpctblock at most once in NewPoWValidBlock #23880
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
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
shaavan
left a comment
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.
reACK fa61dd4
Changes since my last review:
- Fixed a typo.
ser_cpmptblock->ser_cmpctblock. - Rebased over current master.
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.
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
jonatack
left a comment
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.
Nice. Posthumous ACK.
…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.