q126y
q126y

Reputation: 1671

Overhead of In-process function call

According to Refactoring to Patterns

Older languages carried an overhead in subroutine calls, which deterred people from small methods. Modern OO languages have pretty much eliminated that overhead for in-process calls.

How have Modern OO languages eliminated this overhead? Is the author referring to inline functions?

Upvotes: 2

Views: 217

Answers (2)

CoffeDeveloper
CoffeDeveloper

Reputation: 8315

There are 2 evolutions that reduce/nullify the overhead of function calls:

  • CPU evolution:
  • Compiler evolution:

Compilers (also based on profile data) can detect where to inline in order to avoid overhead of small function calls, however compiler alone is only 50% of the work:

Modern CPUs are very good at pipelining and prefecteching; most times it is actually more efficient having many small non-inlined functions so that CPU can correctly prefetech and pipeline them instead of many inlined functions that increase binary size and chance for cache misses.

Since modern CPUs are very powerfull it is worth trying to organize code better (less maintenance = less work = reduced developing costs) than spending time on microoptimizing it (and microoptimization is much better if done by compiler in almost all cases).

Upvotes: 3

V. Kravchenko
V. Kravchenko

Reputation: 1904

I guess so. Also, calls are expensive when they require a lot of parameters to be passed via stack. Author mentioned OO languages, in which a lot of parameters may be wrapped in 'this' pointer, which is passed in ecx register (To see more about __thiscall calling convention https://msdn.microsoft.com/en-us/library/ek8tkfbw.aspx).

Upvotes: 2

Related Questions