Performance Defects

Defects that impact performance of C++ code

These defects detect issues that can lead to performance bottlenecks in C++ code. The detected issues include:

  • Issues that inadvertently cause copy instead of move operations

  • Inefficient or unnecessary temporary variable creation

  • Use of a function that has a possibly more efficient alternative

Polyspace Results

expand all

A move operation may throwThrowing move operations might result in STL containers using the corresponding copy operations
Const parameter values may cause unnecessary data copiesConst parameter values may prevent a move operation resulting in a more performance-intensive copy operation
Const return values may cause unnecessary data copiesConst return values may prevent a move operation resulting in a more performance-intensive copy operation
Const rvalue reference parameter may cause unnecessary data copiesThe const-ness of an rvalue reference prevents intended move operation
Const std::move input may cause a more expensive object copyConst std::move input cannot be moved and results in more expensive copy operation
Empty destructors may cause unnecessary data copiesUser-declared empty destructors prevent autogeneration of move constructors and move assignment operators
std::move called on an unmovable typestd::move used on a class type with no move constructor or move assignment operator
Expensive constant std::string constructionA constant string object is constructed form constant data resulting in inefficient code
Expensive copy in a range-based for loop iterationThe loop variable of a range-based for loop is copied from the range elements instead of being referenced resulting in inefficient code
Expensive local variable copyLocal variable is created by copy from a const reference and not modified later
Expensive pass by valueParameter might be expensive to copy
Expensive return by valueFunctions return large output by value instead of by reference or pointer
Missing constexpr specifierconstexpr specifier can used on expression for compile-time evaluation
Expensive std::string::c_str() use in a std::string operationA string operation uses the output of an std::string::c_str method, resulting in inefficient code
Expensive use of non-member std::string operator+() instead of a simple appendThe non-member std::string operator+() function is called when the append (or +=) method would have been more efficient
Expensive use of std::string methods instead of more efficient overloadAn std::string method is called with a string literal of known length, instead of a single quoted character
Expensive use of std::string with empty string literalUse of std::string with empty string literal can be replaced by less expensive calls to std::basic_string member functions
Inefficient string length computationString length calculated by using string length functions on return from std::basic_string::c_str() instead of using std::basic_string::length()
std::endl may cause an unnecessary flushstd::endl is used instead of the more efficient \n
Use of new or make_unique instead of more efficient make_sharedUsing new or make_unique to initialize or reset shared_ptr results in additional memory allocation
Expensive logical operationA logical operation requires the evaluation of both operands because of their order, resulting in inefficient code

Topics

Bug Finder Defect Groups

The Bug Finder defect checkers are classified into groups such as data flow, concurrency, numerical, and so on.