9021Everyone is running for time,This happens to be$algorithm$Essence of development。
“There is a bunch of functions of code and code without function calls,Which runs faster?”
Let’s talk about conclusions first:The code without function call runs faster。butreadabilityworse,andThe gap between running speed is not large。
We can ask the following questions:
- Why does the frequency call of the function cause a decline in performance?
- How to solve the decline in this performance?
- What is the Internal Union Extension?
Why does the frequency call of the function cause a decline in performance?
Function calls usually involve pressing the parameters into the stack、Jump to function code、Execute function code、Put the return value in the appropriate position、Then jump back to the place where the call function。
How to solve the decline in this performance?
Tailing recursive optimization、Dead code elimination、Constant communication and constant folding、Internal United Development, etc.。This chapter mainly talks about the expansion of the Internal United Nations。
What is the Internal Union Extension
Wikipedia:
Inline expansion is used to eliminate the time overhead (excess time) when a function is called. It is typically used for functions that execute frequently. It also has a space benefit for very small functions, and is an enabling transformation for other optimizations.
Internal expansion is used to eliminate the time overhead of the call function(Excess time)。It is usually used for frequent execution functions。For very small functions,It also has space advantages,And it is a conversion that supports other optimizations。
Frequent calling functions may cause some additional overhead,This overhead is due to the stack operation when the function calls、Factors caused by parameter transmission and return value processing。
To avoid this overhead,The compiler will try to replace the code of the function call to the function body,This process is called the Inner Union Extension(inline expansion)。
ref:
https://www.jstage.jst.go.jp/article/sptj1978/44/3/44_3_206/_pdf
https://www.semanticscholar.org/search?q=Inline%20expansion&sort=relevance