Inline Performance impact

M

m_schellens

I could think of:
Huge inlined function, used (called) from many places
-> program gets huge -> hooks up all memory and the
machine starts to swap.

Cheers,
marc
 
M

ma740988

Rolf said:
Is that the same story on template code, where the implementation is
resident in a .hh file (or a .h file).

class whatever {
public:
template<typename T>
void some_method(T& var) {}
};

If memory serves though, I think implementations in a header file is
already inlined?
 
R

Rolf Magnus

GJ said:
When I mean what scenario ?

If the function gets called from many places, too much inlining can increase
code size significantly, which will lower the cache efficiency on systems
that do use caching (which is the majority these days). On modern
workstation-like computers, the cache is extremely important for fast code
execution. Reading a value from RAM can take several hundred clock cycles.
Similarly, if there is conditional code or a loop in the inline function,
the branch prediction unit gets stressed more.
Unfortunatly, this is not an effect that you can simply measure on a per
function basis to find out whether inlining it is faster or not. It's more
like a tendency, and it likely depends on the CPU model, even for different
CPUs of the same architecture.
 
B

ben

Is that the same story on template code, where the implementation is
resident in a .hh file (or a .h file).

class whatever {
public:
template<typename T>
void some_method(T& var) {}
};

If memory serves though, I think implementations in a header file is
already inlined?

They are, in fact, candidate for inlining. There are lots of functions
that are simply impossible to be inlined.

Even the 'inline' keyword would not guarantee the function to be
actually inlined. The compiler does a great job in deciding whether or
not inlining such a function would give you a performance gain.

Inlining is an optimization technique because it allows more thorough
data flow analysis across caller/callee. Where there's not much to be
optimized from caller/callee data flow analysis, there's not much to be
optimized from inlining, simply.

Ben
 
G

Greg Comeau

They are, in fact, candidate for inlining. There are lots of functions
that are simply impossible to be inlined.

I think the OP was referring to implicitly inlines, which happen
in classes_ not in headers per se. But OP, he's right: just having
a function in a header does not automatically have it being inline'd.
Ditto for using the inline keyword is not the sole determination
for inline'ing nor is its absence (implicitly or otherwise)
the sole determination for not inline'ing. In the end it's
a hint and the compiler can get along w/o it, or use the advise.
 
E

E. Robert Tisdale

Rolf said:
If the function gets called from many places, too much inlining can increase
code size significantly, which will lower the cache efficiency on systems
that do use caching (which is the majority these days).
On modern workstation-like computers,
the cache is extremely important for fast code execution.
Reading a value from RAM can take several hundred clock cycles.
Similarly, if there is conditional code or a loop in the inline function,
the branch prediction unit gets stressed more.
Unfortunatly, this is not an effect that you can simply measure on a per
function basis to find out whether inlining it is faster or not.
It's more like a tendency, and it likely depends on the CPU model,
even for different CPUs of the same architecture.

This is pure nonsense.
You can't contrive an example that will show this.
 
G

Greg

Is that the same story on template code, where the implementation is
resident in a .hh file (or a .h file).

class whatever {
public:
template<typename T>
void some_method(T& var) {}
};

If memory serves though, I think implementations in a header file is
already inlined?

If the implementation of a class method appears within a class
declaration yes it has been declared inline.

Function templates are not declared inline merely by virtue of being
defined in a header file. It is still necessary to specify the inline
keyword if the intent is to declare a function template inline.

Greg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top