473,406 Members | 2,710 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Inline Performance impact

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

--
GJ
Oct 18 '05 #1
9 1513
GJ wrote:
The performance can be DEGRADED by making a function "inline". Is it TRUE
in any case ?


Yes.

Oct 18 '05 #2
GJ

"Rolf Magnus" <ra******@t-online.de> wrote in message
news:dj*************@news.t-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 ?
Oct 18 '05 #3
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

Oct 18 '05 #4

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?

Oct 18 '05 #5
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.
Oct 18 '05 #6
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
Oct 18 '05 #7
In article <43***********************@news.optusnet.com.au> ,
ben <be******@yahoo.com.au> 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?
Oct 18 '05 #8

ma******@gmail.com 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

Oct 18 '05 #9
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.
Oct 18 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Rubén Campos | last post by:
I haven't found any previous message related to what I'm going to ask here, but accept my anticipated excuses if I'm wrong. I want to ask about the real usefulness of the 'inline' keyword. I've...
2
by: Steven T. Hatton | last post by:
I don't really understand the details of what happens when a compiler inlines a given function. I know that basically it's supposed to cause the function to be placed directly on the stack per...
8
by: John Ratliff | last post by:
Can the compiler ever inline a method when there is a pointer to the member used? Thanks, --John Ratliff
1
by: dandorey1 | last post by:
I'm currently in the process of writing a realtime telephony application. I've designed it with a fairly simply plugin architecture. When I first started reading about this the general suggestion...
32
by: Immortal Nephi | last post by:
I want to know if the practice is the best. Do I need to place inline keyword inside class definition or outside member function definition. For example class A { public: A(); ~A();
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.