Function Calls

From ActionScriptWiki

Jump to: navigation, search

Function calls are very expensive in terms of speed. Therefore it makes a lot of sense to inline very simple methods. There is of course a tradeoff since ActionScript does not support inlining of methods. Refactoring or bugfixing inlined code can be a pain since it has been distributed over the whole project.

[edit] Example

Math.abs is a good example for an expensive function call and the tradeoff for inlining a method. Math.abs is so simple that it makes a lot of sense to inline it directly.

[edit] Slow Version

y = Math.abs(x);

[edit] Fast Version

y = x > 0.0 ? x : -x;

Note: There is an even faster version for integer values using Bitwise Operations.

Personal tools