-
Notifications
You must be signed in to change notification settings - Fork 38.8k
refactor: Add performance-no-automatic-move clang-tidy check
#26758
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
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. 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. |
aureleoules
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 9567bfe
| throw std::runtime_error(ToString()); | ||
| } | ||
| const UniValue ret = m_fun(*this, request); | ||
| UniValue ret = m_fun(*this, request); |
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.
I was trying to benchmark this, but couldn't see a difference. Steps to reproduce:
# start bitcoin core with "-rpcuser=user -rpcpassword=password -server=1 -rpcport=12345 -noconnect"
# create a reply with
python3 -c 'ff="ff"*2'000'000;print(f"{{\"jsonrpc\": \"1.0\", \"id\": \"curltest\", \"method\": \"echo\", \"params\": [\"{ff}\"]}}")' > /tmp/data.json
# Run ab
ab -p /tmp/data.json -n 100 -c 1 -A user:password "http://localhost:12345/"
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.
Running with -n 10000 -c 4 I get mean time of 50ms on this branch, 51ms on 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.
I don't know if a +-1 difference is more than noise+rounding error when the resolution is quantized to 1ms.
Either the copy is so cheap that it doesn't matter in the pipe, or the compiler has already optimized away the const?
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.
Indeed, but there is clearly no regression and this PR is about introducing the new clang-tidy rule. It is not about any particular performance improvement but allowing us to automatically check for bad practices. Should we not bother trying to add new clang-tidy rules if there's no performance benefit?
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.
this PR is about introducing the new clang-tidy rule. It is not about any particular performance improvement but allowing us to automatically check for bad practices.
These are almost the same words I was going to put in my own 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.
clang, and gcc likely as well, seem to remove the const already on my machine. So any measurement difference is noise. For reference, on 20ff499 I could see a 6% difference. So if we apply performance related checks, it might be good to prioritize the ones that make a difference. Otherwise we'll get people to change i++ to ++i for integers all over the source code.
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.
Sorry, but I do not realize how not having a performance gain for a particular case with a small UniValue instance on a particular platform makes forcing non-pessimized coding style questionable?
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.
It would be nice to be able to say: "This change has a positive effect on at least one end user or dev" instead of "This change doesn't change the binary and causes merge conflicts"
|
ACK 9567bfe |
performance-no-automatic-move checkperformance-no-automatic-move clang-tidy check
…move` clang-tidy check 9567bfe clang-tidy: Add `performance-no-automatic-move` check (Hennadii Stepanov) Pull request description: Split from bitcoin/bitcoin#26642 as [requested](bitcoin/bitcoin#26642 (comment)). For the problem description see https://clang.llvm.org/extra/clang-tidy/checks/performance/no-automatic-move.html. The following types are affected: - `std::pair<CAddress, NodeSeconds>` - `std::vector<CAddress>` - `UniValue`, also see bitcoin/bitcoin#25429 - `QColor` - `CBlock` - `MempoolAcceptResult` - `std::shared_ptr<CWallet>` - `std::optional<SelectionResult>` - `CTransactionRef`, which is `std::shared_ptr<const CTransaction>` ACKs for top commit: andrewtoth: ACK 9567bfe aureleoules: ACK 9567bfe Tree-SHA512: 9b6a5d539205b41d2c86402d384318ed2e1d89e66333ebd200a48fd7df3ce6f6c60a3e989eda5cc503fb34b8d82526f95e56776e1af51e63b49e3a1fef72dbcb
|
This has been merged. |
…ang-tidy check 9567bfe clang-tidy: Add `performance-no-automatic-move` check (Hennadii Stepanov) Pull request description: Split from bitcoin#26642 as [requested](bitcoin#26642 (comment)). For the problem description see https://clang.llvm.org/extra/clang-tidy/checks/performance/no-automatic-move.html. The following types are affected: - `std::pair<CAddress, NodeSeconds>` - `std::vector<CAddress>` - `UniValue`, also see bitcoin#25429 - `QColor` - `CBlock` - `MempoolAcceptResult` - `std::shared_ptr<CWallet>` - `std::optional<SelectionResult>` - `CTransactionRef`, which is `std::shared_ptr<const CTransaction>` ACKs for top commit: andrewtoth: ACK 9567bfe aureleoules: ACK 9567bfe Tree-SHA512: 9b6a5d539205b41d2c86402d384318ed2e1d89e66333ebd200a48fd7df3ce6f6c60a3e989eda5cc503fb34b8d82526f95e56776e1af51e63b49e3a1fef72dbcb
Split from #26642 as requested.
For the problem description see https://clang.llvm.org/extra/clang-tidy/checks/performance/no-automatic-move.html.
The following types are affected:
std::pair<CAddress, NodeSeconds>std::vector<CAddress>UniValue, also see refactor: Avoid UniValue copies #25429QColorCBlockMempoolAcceptResultstd::shared_ptr<CWallet>std::optional<SelectionResult>CTransactionRef, which isstd::shared_ptr<const CTransaction>