why inline is faster than normal function call?

T

thomas

any other reason except that inline inserts code directly to the
caller while function call push parameters to the stack (which is time
consuming)?
 
S

SG

any other reason except that inline inserts code directly to the
caller while function call push parameters to the stack (which
is time consuming)?

A function call is a boundary the compiler's optimizer can't (easily)
work across. If the code is inlined, this boundary is eliminated and
the optimizer has more information available to improve performance.
 
V

Victor Bazarov

thomas said:
any other reason except that inline inserts code directly to the
caller while function call push parameters to the stack (which is time
consuming)?

Uh... Yes, "time consuming" usually means "slower". Is this a trick
question? If you compare the code generated to call a function versus
to perform the same operations without calling a function, you will
notice that the function calling code contains extra instructions, to
execute which the CPU is bound to spend more time. Among those
instructions are, as you mentioned, the copying of arguments where they
are supposed to go (stack, registers), extracting them from that place
once inside the function body, general preserving of some CPU registers,
restoring them afterwards, and so on. Often with stack-based argument
passing, functions in the beginning contain code to check the stack size
or even integrity, which also uses up some time... If the body of the
function is available to the compiler, the compiler can optimize more
aggressively, thus saving more time. Probably there are other things,
although we're already too far into hardware-specific area...

V
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top