According to this extensive test, the final
keyword does not make the slightest bit of difference performance-wise.
The way final
is used in ActionScript, this comes as no surprise: The final keyword marks only classes and class methods, and thus it affects only inheritance. I see no logical reason why calling a final method should be any faster than calling any other method: The runtime will still need to lookup a function pointer and execute the call.
The same is true for methods and classes in Java. However, in Java, final
also marks references as immutable. And this is a big advantage over its use in ActionScript, because it allows the compiler to "inline" values (i.e. replace all references to the variable in byte code with its actual value, eliminating look-up procedures), which - among other benefits - can speed up performance a bit. Perhaps we will see some use of this in a future version of ActionScript - it would be a good idea for better code clarity and prevention of side-effects, as well.
And for those reasons, I would still consider it good practice to use final
, even when you are not working with other programmers, in cases where the intended behavior requires methods or classes to disallow overrides: It clarifies intent and prevents undesired effects. It will, therefore, speed up development, and that's not such a bad thing, either ;)