Why does the MSVC 10.0 compiler often ignore the inline keyword?

I have a rather complicated C ++ code that is used in a real-time system and, therefore, is absolutely speed sensitive. It was developed on Linux and, to speed up its execution, many functions were marked with the keyword β€œinline” and moved to the header files to allow embedding.

Now I have ported this code to Windows (msvc 10.0, Windows 7) and it works 30% slower. After some profiling, I found out that the problem mainly lies in the fact that many functions are not built-in. When I use "__forceinline", I can easily see acceleration of about 10-20%.

Does anyone have an explanation? Does msvc algorithm work much more conservatively? Or was I just doing something wrong, for example, was there a missing configuration option?

+4
source share
2 answers

You need to check the MSVC optimization settings:

Project Properties -> C/C++ -> Optimization 

There is a parameter here called "Favor size or speed" that significantly changes how ready the compiler is to do.

+5
source

What is inline ?

inline is a keyword that signals to the compiler that the method definition is presented in a string. Usually, a method should be defined in only one TU (the source file, roughly), and inline allows you to define a method in the header that will be included in many different TUs and avoid compiler / linker complaints repeated characters. The linker will combine the characters accordingly.

What is not inline ?

inline does not mean at all that the compiler must inline function. Historically, this may have been used as such, but optimizers have become better and better at deciding when (and not) to embed, and the inline hint has little effect at the moment.

How to ensure compliance with the attachment?

Compilers typically provide specific keywords / attributes that require a "larger" attachment. For example, in MSVC, __forceinline will strongly hint (but still just hint) that the method should be built-in.

+5
source

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


All Articles