[swift-evolution] final class performance
alex at ateamer.de
Thu Jun 23 05:32:50 CDT 2016
AFAIK, Swift applies the same optimisations as for final classes if it can guarantee that the class will not be subclassed. That is, if the class is either private or internal and you have whole module optimisation enabled. If your class, however, is public and not final, there is no way the compiler can assure that it will not be subclassed in a different module and thus cannot perform optimisations like inlining method implementations.
> On 23 Jun 2016, at 09:16, Fabian Ehrentraud via swift-evolution <swift-evolution at swift.org> wrote:
> Somewhere I read that we should always write "final class" where possible, as it is more performant. Is this really the case, especially for non-library modules? Can't the compiler infer whether a class has no subclasses when compiling? Writing "final" just for performance reasons feels wrong.
> -- Fabian
> swift-evolution mailing list
> swift-evolution at swift.org
More information about the swift-evolution