Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Inline Performance impact

Reply
Thread Tools

Inline Performance impact

 
 
GJ
Guest
Posts: n/a
 
      10-18-2005
The performance can be DEGRADED by making a function "inline". Is it TRUE in
any case ?

--
GJ


 
Reply With Quote
 
 
 
 
Rolf Magnus
Guest
Posts: n/a
 
      10-18-2005
GJ wrote:

> The performance can be DEGRADED by making a function "inline". Is it TRUE
> in any case ?


Yes.

 
Reply With Quote
 
 
 
 
GJ
Guest
Posts: n/a
 
      10-18-2005

"Rolf Magnus" <(E-Mail Removed)> wrote in message
news:dj2frb$6lg$05$(E-Mail Removed)-online.com...
> GJ wrote:
>
> > The performance can be DEGRADED by making a function "inline". Is it

TRUE
> > in any case ?

>
> Yes.
>

When I mean what scenario ?


 
Reply With Quote
 
m_schellens@hotmail.com
Guest
Posts: n/a
 
      10-18-2005
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

 
Reply With Quote
 
ma740988@gmail.com
Guest
Posts: n/a
 
      10-18-2005

Rolf Magnus wrote:
> GJ wrote:
>
> > The performance can be DEGRADED by making a function "inline". Is it TRUE
> > in any case ?

>
> Yes.

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?

 
Reply With Quote
 
Rolf Magnus
Guest
Posts: n/a
 
      10-18-2005
GJ wrote:

>> > The performance can be DEGRADED by making a function "inline". Is it

> TRUE
>> > in any case ?

>>
>> Yes.
>>

> 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.


 
Reply With Quote
 
ben
Guest
Posts: n/a
 
      10-18-2005
> 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
 
Reply With Quote
 
Greg Comeau
Guest
Posts: n/a
 
      10-18-2005
In article <4354fdff$0$20333$(E-Mail Removed)> ,
ben <(E-Mail Removed)> wrote:
>> 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.


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.
--
Greg Comeau / Celebrating 20 years of Comeauity!
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
 
Reply With Quote
 
E. Robert Tisdale
Guest
Posts: n/a
 
      10-18-2005
Rolf Magnus wrote:

> 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.
 
Reply With Quote
 
Greg
Guest
Posts: n/a
 
      10-18-2005

http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Rolf Magnus wrote:
> > GJ wrote:
> >
> > > The performance can be DEGRADED by making a function "inline". Is it TRUE
> > > in any case ?

> >
> > Yes.

> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Performance Impact of ASP.NET 1.1 and 2.0 Side by Side Rich ASP .Net 6 01-24-2007 10:54 PM
Performance impact of using decorators vinjvinj Python 13 03-11-2006 08:39 AM
import keyword behaviour - performance impact if used multipletimes? Andrew James Python 4 01-15-2005 03:44 AM
Can Novell Security impact ASP.NET performance? Scott Cadillac ASP .Net 0 10-25-2003 04:40 PM
runtime performance impact of template usage Aaron Anodide C++ 9 07-30-2003 06:45 AM



Advertisments