주요 콘텐츠

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 결과

모두 확장

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 (R2021a 이후)
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
Expensive return of a const objectThe return statement of a function copies an objects instead of moving it because the returned object is declared as a const (R2022a 이후)
Move operation uses copyNon-const rvalue reference parameter of a function or operator is copied instead of moved (R2021b 이후)
std::move called on an unmovable typestd::move used on a class type with no move constructor or move assignment operator
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 (R2021a 이후)
Expensive member initializationYou assign values to class members in the constructor body instead of constructing members using a member initializer list (R2023b 이후)
Expensive pass by valueParameter might be expensive to copy
Expensive return by valueFunctions return large output by value instead of by reference or pointer
Expensive use of std::any_castAn object is cast by-value using std::any_cast when casting by-reference is more efficient (R2023b 이후)
Expensive construction of std::string or std::regex from constant stringA constant std::string or std::regex object is constructed from constant data, resulting in inefficient code
Missing constexpr specifierconstexpr specifier can be used on variable or function for compile-time evaluation
Unnecessary construction before reassignmentInstead of directly constructing objects with value, you construct objects and then immediately assign values to objects (R2023a 이후)
Expensive unused objectExpensive local object is constructed but not used (R2024a 이후)
Expensive std::function type definitionDefinition of std::function type uses pass-by-value semantics for arguments that are expensive to copy (R2024a 이후)
Expensive dynamic castExpensive dynamic_cast is used instead of more efficient static_cast or const_cast (R2021b 이후)
Expensive use of a standard algorithm when a more efficient method existsFunctions from the algorithm library are misused with inappropriate inputs, resulting in inefficient code (R2021b 이후)
Expensive use of container's count methodThe function member count() of a container is used for checking if a key is present, leading to inefficient code (R2021b 이후)
Expensive use of container's insertion methodsOne of the insertion methods of a container is used to insert a temporary object (R2022a 이후)
Expensive use of container's size methodA container's size() method is used for checking emptiness instead of its empty() method, which is more efficient (R2022b 이후)
Expensive use of map's bracket operator to insert or assign a valueThe bracket operator of std::map or std::unordered_map is used for inserting or assigning a value in the container instead of the insert_or_assign() method, which is more efficient (R2022b 이후)
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 (R2021a 이후)
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 (R2021a 이후)
Expensive use of string functions from the C standard libraryString functions from the C standard library are used inefficiently (R2022a 이후)
Expensive use of substr() to shorten a std::stringThe method std::string::substr() is called to shorten an std::string object (R2022a 이후)
Inefficient use of sprintfThe function sprintf, snprintf, or swprintf copies strings instead of the more efficient strcpy, strncopy, or wcsncpy (R2021b 이후)
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 (R2021a 이후)
Unnecessary use of std::string::c_str() or equivalent string methodsInstead of a std::string object, a string operation uses the C-string obtained from std::string functions including std::string::c_str, std::string::data(), std::string::at(), or std::string::operator[], resulting in inefficient code
Expensive logical operationA logical operation requires the evaluation of both operands because of their order, resulting in inefficient code (R2021a 이후)
Expensive return caused by unnecessary std::moveAn unnecessary call to std::move in the return statement hinders return value optimization, resulting in inefficient code (R2022b 이후)
Expensive allocation in loopFixed sized memory is allocated or deallocated in a loop (R2022a 이후)
Expensive post-increment operationObject is post-incremented when pre-incrementing is faster (R2021b 이후)
Inefficient use of for loopRange-based for loop can perform equivalent iteration more efficiently (R2022a 이후)
Missing call to container's reserve methodA fixed number of items are added to a container without calling the reserve() method of the container beforehand, resulting in inefficient code (R2022b 이후)
Unnecessary PaddingMembers of a struct are padded to fulfill alignment requirement when rearranging the members to fulfill this requirement saves memory (R2021b 이후)
Unnecessary implementation of a special member functionImplementing special member functions hinders code optimization when implicit versions are equivalent (R2023a 이후)
Unnecessary reference to parameterParameter is passed to function as const reference when passing by value is more efficient (R2024a 이후)

도움말 항목

  • Bug Finder Defect Groups

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