Improving speed
There are a few techniques that can simply improve code performance. Let's jump directly to the first one.
Final
You can make a function and property declaration with the final
attribute. Adding the final
attribute makes it nonoverridable. Subclasses can't override that method or property. When you make a method nonoverridable there is no need to store it in the vtable and the call to that function can be performed directly without any function address lookup in the vtable:
class Animal { final var name: String = "" final func feed() { } }
As you have seen, the final
method performs faster than nonfinal. Even so small an optimization can improve application performance. It not only improves performance but also makes the code more secure. This way you disable the method from being overridden and prevent unexpected and incorrect behavior.
Enabling the Whole Module Optimization setting achieves very similar optimization results but it's better to mark a function and property...