Ideas for Good Performance Optimization in C ++

Well, I sat in front of the profiling results for the last three days, created using a fairly wide range of test cases using an automation suite. The idea is to see if there are good optimization solutions that can improve performance. I will be well versed in this context as follows:

  • The performance potential is an improvement that is significant and observable at the end of the user level, for example. > 100% improvement in an inefficient area.

  • Has the potential for basic space reduction in use, for example. > 50% reduction in heavy data area.

  • Easy to implement, with minimal code obfuscation and minimal side effects. those. The benefits are significantly cost optimization costs.

The application is a set of 3D maps and simulations with a large number of graphics in the interface and geometric processing on the rear panel. I have already done a lot to ensure the optimal choice of algorithm for most of the processing, and at this stage I am looking for any generally applicable simple ways to get this extra bit when working with large and complex data sets. So far I have come up with the following:

  • When searching, keep a buffer of the most recently found items and check this first. It seems that a lot of repetitive search processing is being scanned in the same area. From the answers to date, this looks like a special form of memoization

  • When sorting, check that the data is not yet in sort order (in particular where qsort is used)

  • Save the GUI and process it in separate streams (does not meet good criteria that are easy to implement, but IMO is still worth it)

  • If you have local class variables that have significant build / break times in heavily used member functions, they make them private members of the class. It is noteworthy that for dynamic arrays and strings, especially for MFC CArrays and CStrings.

  • When using dynamic arrays, set the initial size so that it slightly exceeds typical use, and have an exponential growth strategy.

  • , , , .

  • , , , .

    CString MyFunc (double x, double y)

,

void  MyFunc(double x, double y, CString &Result)

, CStrings MFC . (Edit: RVO, CStrings )

, , , , - , , ?

: , . , , , , , . , , , , ( ) , , , . , , . , , , , . , , .

FWIW, , , 12% , .

: , , , .

?

++ Linux?

+5
9

CString MyFunc(double x, double y)

,

void MyFunc(double x, double y, CString &Result)

MyFunc , . NRVO. , , - , , . " ", , NRVO .

, :

  • memoization ( , /, ).
  • , (, , ints, ).
  • ( - - ). (, Sorted<T>), . , a Sorted<vector<T> >, , , , vector<T>, a Sorted<vector<T> >, . , , , , .
  • .. , , , . - , , .
  • flyweight .
  • , , . . , .
+5

, " - " ,

, , :

, . , " - ".

.

? . . YMMV.

. FWIW, 12% , .

, , .

, , , , , - . , :

  • , .

: , RVO: , , : move library Adobe. , Boost - .

# 2: :

  • .
+9

, , - ( ).

, , , - . , , SIMD, , , , , , , , . .

, , .

+3

. ; . , , ; , . , , , , CPU.

, , . , . , , !

, . , , , - - -, , , .

, , .

+3

. , / . , NRVO.

inline. , - " ".

97% . , , 97% . 3% , . (, , " ". , , , , , , 1) 2) )

, : , . , 3% , .

(, ): .

: , . , , . - . , , , , . , SIMD, , . , , . , FP . FP , . . . , , , . , ( CPU), . , .

" ", ? . , . .

: , ++. , reallocs MFC. , "C ". . std::vector . , std::string. ++ , . MFC.

+3

, . qsort(). , std::sort() qsort(). , , 2: 1 , 5: 1 10: 1.

+3

,

, . , :

  • " , ", . , , .

  • do , , . .

. .

... . , .

+2

+1 .

, , . . , , . end rant

, 97% . 80/20 - 20% 80% , , , , . ...

- , . . , .

, , :

  • . .

  • . quicksort - , , .

  • - , ( ) " , ".

  • , .

  • , /, , . , , .

  • , - , , , , .

+1

If you run the code under the sampling profiler and find that there are some intensive calculations that take up a significant part of the time, then there are many microoptimizations that can be considered, up to using SIMD, if you can limit your support to a specific processor (s) .

0
source

All Articles