⬆️ ⬇️

C ++ performance on modern PCs

In view of the restrictions on the size, I publish a note in the form of an article, and not as a link with annotation.


Since the times when C ++ was designed, the relative (to the speed of the RAM) processor speed has increased 400 times. Plus, the processor has big caches and branch prediction in the code. All this together seriously affects the efficiency of C ++ on modern platforms. Below I give an abstract and a couple of links where it is proposed to use these facts to improve the efficiency of the code.





The statement of the problem was met by me in this article:

solid-angle.blogspot.com/2010/02/musings-on-data-oriented-design.html



I recommend also to carefully read the report and articles, the links to which are published by the author at the beginning. The report is the most informative and indicative in terms of specific figures:

research.scee.net/files/presentations/gcapaustralia09/Pitfalls_of_Object_Oriented_Programming_GCAP_09.pdf

Using the example of three-dimensional graphics objects, it is shown that the simplest changes from the point of view of C ++ (for example, the redistribution of ads in the class header) are a significant increase in the speed of the code.

')

The author of the article speaks about the need to create code based on data, and only then OOP abstractions (Data-Oriented design). Taking into account the changed difference in the speed of memory and the processor (recall: a hundred times!), This can globally speed up the work of the code on modern systems. In simple terms, the approach suggests:

1) rejection of functions that work with a single data element in cases where there are many similar elements

2) the organization of these elements as a separate continuous array in memory, plus member functions working directly with this array.



From the point of view of the PC, as the authors write, information of different types should be organized into homogeneous arrays, one for each data type. At the assembler level (or another low-level language), the functions must be generated in such a way that the processing unit must be an array or a set of them. At the same time, for a person (for example, during debugging), these data should be grouped into classes (that is, the usual way for modern C ++), the data of which represent a heterogeneous set of elements of low-level homogeneous arrays. This can speed up the code by an order of magnitude (or more in some cases).



PS For some, the concept of data-oriented design may not be new. It is quite possible that you have experience in implementing this approach and specific results of its application. It would be very interesting if you shared your experience with similar optimization in the comments.

Source: https://habr.com/ru/post/85481/



All Articles