inline - What is the benifit of inlining methods -


i've seen util class written friend having many inline methods. class images , has methods like

public static inline function resize ( img:image, width:int, height:int) {     //... method implementation goes here. } 

i've asked him why usage of inline. know compiler changes

var img:image = imgutil.resize(img, 100, 100); 

to

var img:image = // implementation of method here 

he said reduces calls functions , use them on utility methods. doesn't copying same code every time increase program size?

is needed nowadays? if needed, when should 1 use them?

edit

i'm listing problems , advantages in list given in link patrick provided future viewers don't want go through links.

problems

replacing call site expanded function body can worsen performance in several ways :

  • in applications code size more important speed, such many embedded systems, inlining disadvantageous except small functions, such trivial mutator methods.
  • the increase in code size may cause small, critical section of code no longer fit in cache, causing cache misses , slowdown.
  • the added variables inlined procedure may consume additional registers, , in area register pressure high may force spilling, causes additional ram accesses.
  • a language specification may allow program make additional assumptions arguments procedures can no longer make after procedure inlined.
  • if code size increased much, resource constraints such ram size may exceeded, leading programs either cannot run or cause thrashing. today, unlikely issue desktop or server computers except aggressive inlining, can still issue embedded systems.

typically, compiler developers keep these issues in mind, , incorporate heuristics compilers choose functions inline improve performance, rather worsening it, in cases.

advantages:

inline expansion optimization, since eliminates overhead calls, more important enabling transformation. is, once compiler expands function body in context of call site—often arguments may fixed constants -- may able variety of transformations not possible before. example, conditional branch may turn out true or false @ particular call site. in turn may enable dead code elimination, loop-invariant code motion, or induction variable elimination.

wikipedia tell more need that.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -