I’m just looking into recommendations for our team around optimizations.
In this optimization guide it mentions the recommendation to add the
final keyword to reduce dynamic dispatch. Through other talks and threads, it has also been mentioned that
final is inferred during Whole Module Optimization builds for non-open classes as there is no possibility of overriding these classes after the fact.
Considering that WMO builds are the default for Xcode release builds now, should this guidance be updated to reflect that this is unnecessary in these circumstances?
I’ve noticed many workplaces I’ve written Swift code require prepending all classes with
final as a matter of policy for the optimization potential. Doesn’t this setting, however, make such requirements redundant? Also, doesn’t this negate the power of the keyword in actually enforcing at compile time a restriction when it’s actually important that a class, property or method should not be overridden by subclasses?
I’m curious what those here who work on the language think the best recommendations are, and whether we could update documentation to clear this up.