views:

1051

answers:

2

As the title says really. Does the virtual keyword cause a performance hit?

+3  A: 

First off, in Actionscript you don't need to explicitly mark a method to be overridden as virtual as you do in C#, the compiler will do this for you. This is why the keyword doesn't show up in any docs because it is irrelevant from the developers perspective.

To answer your question though, which is whether overriding a method makes it slower, the answer is no as long as your class is sealed, meaning you don't use the 'dynamic' keyword when defining the class.

The reason why is that when constructing a sealed class, you're going to have explicit markers to every method for that object, when overriding a method you get a marker directly to the new function, the class does not have to look it up at runtime like in a dynamic class.

seanalltogether
+1  A: 

All methods are virtual in AS3 right now. But my guess is 'virtual' will become enforced in a future version of AS poss. via some compiler option setting.

Scott Evernden