refactor: Add performance-no-automatic-move clang-tidy check #26758

pull hebasto wants to merge 1 commits into bitcoin:master from hebasto:221227-tidy-nam changing 12 files +19 −17
  1. hebasto commented at 3:47 pm on December 27, 2022: member

    Split from bitcoin/bitcoin#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 bitcoin/bitcoin#25429
    • QColor
    • CBlock
    • MempoolAcceptResult
    • std::shared_ptr<CWallet>
    • std::optional<SelectionResult>
    • CTransactionRef, which is std::shared_ptr<const CTransaction>
  2. clang-tidy: Add `performance-no-automatic-move` check
    https://clang.llvm.org/extra/clang-tidy/checks/performance/no-automatic-move.html
    9567bfeab9
  3. DrahtBot commented at 3:47 pm on December 27, 2022: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK aureleoules, andrewtoth

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #26642 (clang-tidy: Add more performance-* checks and related fixes by hebasto)
    • #26039 (refactor: Run type check against RPCArgs (1/2) by MarcoFalke)
    • #25778 (fuzz: Modify tx_pool_standard target to test package processing by chinggg)
    • #25093 (rpc: Check for omitted, but required parameters by MarcoFalke)

    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.

  4. aureleoules approved
  5. aureleoules commented at 2:46 pm on December 28, 2022: member
    ACK 9567bfeab95cc0932073641dd162903850987d43
  6. in src/rpc/util.cpp:582 in 9567bfeab9
    578@@ -579,7 +579,7 @@ UniValue RPCHelpMan::HandleRequest(const JSONRPCRequest& request) const
    579     if (request.mode == JSONRPCRequest::GET_HELP || !IsValidNumArgs(request.params.size())) {
    580         throw std::runtime_error(ToString());
    581     }
    582-    const UniValue ret = m_fun(*this, request);
    583+    UniValue ret = m_fun(*this, request);
    


    maflcko commented at 3:56 pm on December 28, 2022:

    I was trying to benchmark this, but couldn’t see a difference. Steps to reproduce:

    0# start bitcoin core with "-rpcuser=user -rpcpassword=password -server=1 -rpcport=12345 -noconnect"
    1# create a reply with
    2python3 -c 'ff="ff"*2'000'000;print(f"{{\"jsonrpc\": \"1.0\", \"id\": \"curltest\", \"method\": \"echo\", \"params\": [\"{ff}\"]}}")' > /tmp/data.json
    3# Run ab
    4ab -p /tmp/data.json -n 100 -c 1 -A user:password "http://localhost:12345/"
    

    andrewtoth commented at 4:45 pm on December 28, 2022:
    Running with -n 10000 -c 4 I get mean time of 50ms on this branch, 51ms on master.

    maflcko commented at 4:07 pm on December 30, 2022:

    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?


    andrewtoth commented at 10:55 pm on December 30, 2022:
    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?

    hebasto commented at 10:26 am on December 31, 2022:

    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 :)


    maflcko commented at 2:33 pm on December 31, 2022:
    clang, and gcc likely as well, seem to remove the const already on my machine. So any measurement difference is noise. For reference, on 20ff4991e548630d7bb5e491fa4d69ec49369872 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.

    hebasto commented at 2:45 pm on December 31, 2022:
    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?

    maflcko commented at 3:18 pm on January 11, 2023:
    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”
  7. andrewtoth commented at 4:47 pm on December 28, 2022: contributor
    ACK 9567bfeab95cc0932073641dd162903850987d43 Verified all lines changed give a performance-no-automatic-move error if the const is not removed, and only those lines changed give that error.
  8. maflcko renamed this:
    clang-tidy: Add `performance-no-automatic-move` check
    refactor: Add `performance-no-automatic-move` clang-tidy check
    on Jan 11, 2023
  9. DrahtBot added the label Refactoring on Jan 11, 2023
  10. maflcko referenced this in commit 9887fc7898 on Jan 11, 2023
  11. fanquake commented at 3:22 pm on January 11, 2023: member
    This has been merged.
  12. fanquake closed this on Jan 11, 2023

  13. sidhujag referenced this in commit 3b0597af60 on Jan 11, 2023
  14. hebasto deleted the branch on Jan 12, 2023
  15. bitcoin locked this on Jan 12, 2024

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-11-17 12:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me