cpp-performance
C++ Performance
Use this skill when C++ code may pay avoidable runtime cost: copies that could be references or moves, allocations that could be hoisted or reserved, move-enabling operations that the compiler will silently downgrade to copies, or library calls that have a cheaper equivalent with identical semantics.
The goal is to remove waste that does not change observable behavior: every expensive copy has a justification, every move actually moves, every container and string operation uses the cheapest correct form, and every type that participates in moves or containers is noexcept where the standard library rewards it.
UTILITY SKILL. INVOKES: read-only file access for supplied targets; no other tools or skills. FOR SINGLE OPERATIONS: use for focused copy/allocation review, move-semantics correctness, noexcept audit, or hot-path tuning.
The clang-tidy performance-* checks are the canonical catalog this skill encodes, plus a small set of cost-relevant checks from the modernize-*, bugprone-*, readability-*, and clang-analyzer-* namespaces (see Related Checks Outside The performance-* Namespace); cite the matching check name in findings so the reader can cross-reference and optionally automate the fix.
Scope
- Use this skill for: unnecessary copies (value parameters, copy-initialized locals, range-for loop variables, implicit conversions in range-for), broken or pointless
std::move(move of const, move of trivially-copyable, move into a const-ref sink, missingstd::moveon a copy-assigned local,constlocals that block automatic move on return), move constructors that copy a base or member, missingnoexcepton move constructor / move assignment /swap/iter_swap/ destructor, inefficient container growth (push_back/emplace_backin a loop withoutreserve), inefficient string building (operator+chains instead of+=/append), STL free-function algorithms on associative containers that have a method form,std::endlwhere'\n'suffices,float-to-doublepromotion in C math functions, oversized enum underlying types, integer-to-pointer casts that lose provenance, redundantstring/string_viewconversions, single-character string-literal arguments tofind/+=family, and out-of-line defaulted destructors that block trivial destructibility. - Use it also for the closely-related cost checks in other namespaces:
emplacevs insert-of-temporary (modernize-use-emplace), pass-by-value-and-move constructors (modernize-pass-by-value), the erase-remove idiom (bugprone-inaccurate-erase),empty()vssize() == 0(readability-container-size-empty),contains()vscount/find(readability-container-contains), redundantc_str()/data()(readability-redundant-string-cstr), and struct padding (clang-analyzer-optin.performance.Padding). - Apply it to API signatures (by-value vs by-const-ref vs by-value-and-move), data-member and return-value move flow, type definitions that go into standard containers, and tight loops where per-iteration cost multiplies.
- Keep the review centered on runtime cost with preserved semantics. The performance fix must be a behavior-preserving transformation; if a cheaper form changes observable behavior, lifetime, or exception guarantees, it is out of scope as a pure performance change.