chore: Enable remaining clang-tidy performance checks#6648
chore: Enable remaining clang-tidy performance checks#6648godexsoft wants to merge 7 commits intoXRPLF:developfrom
performance checks#6648Conversation
| [](auto...) {}); | ||
| }; | ||
| }(std::move(std::as_const(s1)))); | ||
| }(std::move(std::as_const(s1)))); // NOLINT(performance-move-const-arg) |
There was a problem hiding this comment.
I believe these are deliberately doing the "wrong" thing here
There was a problem hiding this comment.
s1 is a MultiApiJson which contains only one std::array so it is trivially copyable. I think clang-tidy is right here and in the other similar places where you've added nolint
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #6648 +/- ##
=======================================
Coverage 81.4% 81.5%
=======================================
Files 998 998
Lines 74456 74454 -2
Branches 7574 7556 -18
=======================================
+ Hits 60624 60643 +19
+ Misses 13832 13811 -21
🚀 New features to boost your workflow:
|
|
This PR has conflicts, please resolve them in order for the PR to be reviewed. |
|
All conflicts have been resolved. Assigned reviewers can now start or resume their review. |
| // Right now no move will occur; With c++-20 child will | ||
| // be moved from. | ||
| node = intr_ptr::static_pointer_cast<SHAMapInnerNode>(std::move(child)); | ||
| node = intr_ptr::static_pointer_cast<SHAMapInnerNode>(child); |
There was a problem hiding this comment.
Probably not related, but what is the comment here about if all the nodes are operated by pointers?
| auto nftPage = std::make_shared<SLE>(keylet::nftpage( | ||
| keylet::nftpage_max(A1), (nfTokens[1].getFieldH256(sfNFTokenID)))); | ||
| nftPage->setFieldArray(sfNFTokens, std::move(nfTokens)); | ||
| nftPage->setFieldArray(sfNFTokens, nfTokens); |
There was a problem hiding this comment.
We remove std::move() here and in the other places because the object is trivially copyable, right?
| [](auto...) {}); | ||
| }; | ||
| }(std::move(std::as_const(s1)))); | ||
| }(std::move(std::as_const(s1)))); // NOLINT(performance-move-const-arg) |
There was a problem hiding this comment.
s1 is a MultiApiJson which contains only one std::array so it is trivially copyable. I think clang-tidy is right here and in the other similar places where you've added nolint
There was a problem hiding this comment.
Pull request overview
This PR enables several previously-disabled clang-tidy performance-* checks and updates the codebase to satisfy the new diagnostics, largely by removing ineffective std::move calls, avoiding unnecessary copies in range-for loops, and reserving vector capacity where appropriate.
Changes:
- Enable additional clang-tidy performance checks in
.clang-tidy. - Mechanical refactors across RPC/overlay/app/lib/test code to comply with the new checks (string
findchar overloads, range-for byconst&, remove ineffective moves, addreserve()). - A few small signature/initializer updates to avoid “move-const-arg”/“no-automatic-move” warnings.
Reviewed changes
Copilot reviewed 58 out of 58 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/xrpld/rpc/handlers/ServerDefinitions.cpp |
Use find(char) overload for faster string search. |
src/xrpld/rpc/handlers/NoRippleCheck.cpp |
Remove ineffective std::move from optional value extraction. |
src/xrpld/rpc/handlers/LedgerEntry.cpp |
Remove ineffective std::move when passing sorted credentials. |
src/xrpld/rpc/handlers/GatewayBalances.cpp |
Remove ineffective moves; avoid extra copies in inserts where possible. |
src/xrpld/rpc/handlers/DepositAuthorized.cpp |
Remove ineffective std::move from optional value extraction. |
src/xrpld/rpc/handlers/AccountTx.cpp |
Allow move/avoid const-inhibiting patterns for status locals. |
src/xrpld/rpc/handlers/AccountOffers.cpp |
Remove ineffective std::move from optional value extraction. |
src/xrpld/rpc/handlers/AccountLines.cpp |
Remove ineffective std::move from optional value extraction. |
src/xrpld/rpc/handlers/AccountInfo.cpp |
Remove ineffective std::move from optional value extraction. |
src/xrpld/rpc/handlers/AccountCurrenciesHandler.cpp |
Remove ineffective std::move from optional value extraction. |
src/xrpld/rpc/handlers/AccountChannels.cpp |
Remove ineffective std::move from optional value extraction. |
src/xrpld/rpc/handlers/AMMInfo.cpp |
Remove ineffective std::move of const shared_ptr-like value. |
src/xrpld/rpc/detail/ServerHandler.cpp |
Use find(char) for header parsing. |
src/xrpld/rpc/detail/RPCCall.cpp |
Use find_last_of(char); remove ineffective move into Json::Value; add clarifying comments. |
src/xrpld/overlay/detail/OverlayImpl.cpp |
Remove ineffective move from const&; range-for by const&. |
src/xrpld/app/rdb/backend/detail/SQLiteDatabase.cpp |
Avoid moving blobs when only read-only access is needed. |
src/xrpld/app/misc/detail/ValidatorSite.cpp |
Avoid moving response when downstream takes const&. |
src/xrpld/app/misc/detail/ValidatorList.cpp |
Range-for by const&; avoid const-inhibiting locals. |
src/xrpld/app/misc/NetworkOPs.cpp |
Adjust TxQ::Metrics parameter passing and initialization style. |
src/xrpld/app/main/Main.cpp |
Add reserve() before filling child-process vector. |
src/xrpld/app/main/GRPCServer.cpp |
Use find_first/last_of(char); remove ineffective move for small enum-like field. |
src/xrpld/app/main/Application.cpp |
Range-for by const& for startup RPC commands. |
src/xrpld/app/ledger/detail/LedgerMaster.cpp |
Remove ineffective move into const& parameter. |
src/xrpld/app/consensus/RCLValidations.cpp |
Remove ineffective move into const& parameter. |
src/xrpld/app/consensus/RCLCxPeerPos.h |
Change proposal parameter passing to satisfy performance checks. |
src/xrpld/app/consensus/RCLCxPeerPos.cpp |
Match constructor signature/initialization to header. |
src/test/protocol/MultiApiJson_test.cpp |
Add NOLINT for intentional move-const-arg usage in static-assert tests. |
src/test/ledger/Directory_test.cpp |
Range-for by const&. |
src/test/jtx/impl/mpt.cpp |
Range-for by const&. |
src/test/jtx/impl/AMMTest.cpp |
Avoid const local that could inhibit moves/copies per tidy. |
src/test/consensus/Validations_test.cpp |
Range-for by const&; add reserve() for expected fee vector. |
src/test/conditions/PreimageSha256_test.cpp |
Range-for by const&. |
src/test/beast/aged_associative_container_test.cpp |
Range-for by const&. |
src/test/basics/IntrusiveShared_test.cpp |
Add reserve() for thread vectors. |
src/test/app/Vault_test.cpp |
Avoid const local that could inhibit moves/copies per tidy. |
src/test/app/ValidatorSite_test.cpp |
Add reserve() for URI collection. |
src/test/app/ValidatorList_test.cpp |
Add reserve() for publisher key strings. |
src/test/app/Transaction_ordering_test.cpp |
Add reserve() and replace magic number with constant. |
src/test/app/RCLValidations_test.cpp |
Range-for by const&. |
src/test/app/Offer_test.cpp |
Range-for by const&. |
src/test/app/Manifest_test.cpp |
Remove ineffective std::move into const& overload. |
src/test/app/Loan_test.cpp |
Avoid copies in lambda returns; add reserve() for broker vector. |
src/test/app/LedgerReplay_test.cpp |
Add reserve() for skip-list vector. |
src/test/app/Invariants_test.cpp |
Remove ineffective moves into const& APIs. |
src/test/app/Batch_test.cpp |
Add reserve() for txn id strings. |
src/libxrpl/tx/transactors/oracle/OracleSet.cpp |
Remove ineffective moves from const& elements. |
src/libxrpl/tx/transactors/nft/NFTokenUtils.cpp |
Remove ineffective move into const& overload. |
src/libxrpl/tx/transactors/nft/NFTokenAcceptOffer.cpp |
Remove ineffective move into const& overload. |
src/libxrpl/tx/transactors/bridge/XChainBridge.cpp |
Avoid const local that could inhibit moves/copies per tidy. |
src/libxrpl/tx/invariants/VaultInvariant.cpp |
Remove ineffective std::move in returns. |
src/libxrpl/tx/invariants/PermissionedDomainInvariant.cpp |
Remove ineffective move of trivially-copyable struct. |
src/libxrpl/shamap/SHAMap.cpp |
Remove move of child and rely on consistent behavior. |
src/libxrpl/protocol/STPathSet.cpp |
Range-for by const&. |
src/libxrpl/protocol/BuildInfo.cpp |
Range-for by const&. |
src/libxrpl/ledger/helpers/TokenHelpers.cpp |
Avoid const local that could inhibit moves/copies per tidy. |
src/libxrpl/ledger/Ledger.cpp |
Remove ineffective move/copy patterns; range-for by const&. |
src/libxrpl/basics/FileUtilities.cpp |
Remove const local to preserve move behavior on return. |
.clang-tidy |
Enable remaining clang-tidy performance checks. |
Comments suppressed due to low confidence (1)
src/xrpld/app/misc/NetworkOPs.cpp:207
TxQ::Metricsis not trivially copyable (it containsstd::optional), so the inline comment is misleading. Since the ctor takesescalationMetricsby value, initializingemfromescalationMetricscopies; consider moving it into thestd::optionalto avoid an extra copy when the caller provides a temporary.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // The semantics of this changes when we move to c++-20 | ||
| // Right now no move will occur; With c++-20 child will | ||
| // be moved from. |
There was a problem hiding this comment.
The comment about move semantics changing "when we move to c++-20" is now misleading: the code no longer uses std::move(child) here, so the described behavior doesn’t apply. Please update or remove the comment so it matches the current code and C++20 build settings.
| // The semantics of this changes when we move to c++-20 | |
| // Right now no move will occur; With c++-20 child will | |
| // be moved from. |
| RCLCxPeerPos( | ||
| PublicKey const& publicKey, | ||
| Slice const& signature, | ||
| uint256 const& suppress, | ||
| Proposal&& proposal); | ||
| Proposal const& proposal); // trivially copyable |
There was a problem hiding this comment.
The constructor now takes Proposal const& and the comment says "trivially copyable", but ConsensusProposal is not trivially copyable (it contains e.g. std::optional). Also, taking by const-ref forces a copy when callers pass a temporary (see PeerImp.cpp constructing a Proposal{...} inline). Consider taking Proposal by value and moving into proposal_, or providing both const&/&& overloads, and remove/adjust the "trivially copyable" comment to match reality.
High Level Overview of Change
This PR enables the following clang-tidy checks:
API Impact
No impact.