C++ overhead in method header

Asked

Viewed 155 times

6

I’ve been analyzing the performance of a Directx renderer through the VS2015 Performance Profiler tool and it pointed me to an overhead in the header of a very requested renderer method, as shown below:

inserir a descrição da imagem aqui

The parameters are being passed by reference, with the exception of Primitivetype, which is an Enum.

There are other methods that are also very requested, but do not feature any overhead in your header.

What could be causing this?

  • 1

    I think he’s showing that there’s a big consumption in the whole method, then showing the specific parts where he spends more time inside it.

  • I thought about it, but adding up the internal consumption of the method, the sum is only 3%

  • Wouldn’t be the copy? It seems to me that type is being passed by value.

  • I don’t think so, because Primitivetype is an Enum. I think it might be a Profiler bug. Maybe he isn’t able to identify any lines, and is throwing the load to the header.

  • 2

    "Overhead in the method header" is a sentence that has no meaning in the context of the C++ language. If there is overhead it is in the execution function (or method).

  • But if I am receiving a relatively large object per parameter, as value and not as reference, there will be a processing to generate a copy of this correct object?

  • 2

    But then it would be in the "call", and not in the header...you are using "header" where it should be "called", e. g: the title should be "overhead na calling for of the method.

  • Got it @José X. So it really must be a misinformation of Profiler.

  • In my humble opinion the overhead pointed would be by the use of the Idirect3dtexture9 interface (which does not set up an overhead in the header but rather in the use of the parameter in the method). Virtual methods cannot be optimized as inline by the compiler and a vtable scan is also required to identify which method (base or particular child class) is suitable for each use.

Show 4 more comments

1 answer

0

The Primitivetype parameter may be causing this overhead, as a copy of values is made for each method call. In C++ there is a "cat jump" to avoid overhead that a type per value can cause when passed as parameter to a function/method. The function should receive a reference const of that type instead, for example:

//Overhead por conta da copia de valores.
int soma(int a, int b); 

//Passa a própria referência, e impede que elas sejam alteradas internamente na função.
int soma(const int& a, const int& b);

In your case Primitivetype could be passed the same way:

Renderer::AddVertex(Vertex* vertex, const PrimitiveType& type, IDirect3DTexture* texture)

And don’t worry, it doesn’t change anything in the method call.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.