Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift: private / fileprivate runtime performance

I'm aware of the fact that there shouldn't be runtime performance differences when moving methods of a class to extensions (as answered in Swift extension and are extensions bad for performance in swift?).

But I can not find much documentation about if there is any difference in runtime performance by changing the necessary private properties to fileprivate, which is generally needed in order to allow the methods (moved to an extension in the same file as the class), to access them.

Is anyone aware of any performance difference? (I don't care about compile time differences, which I think do not exist in this case anyway, just runtime.)

like image 561
nbloqs Avatar asked Apr 11 '26 22:04

nbloqs


1 Answers

Why would there be such a difference? These privacy terms are mostly just notes to the compiler to forbid certain kinds of access.

The important gains at runtime come from using Whole Module Optimization and/or declaring your classes final. This allows dynamic dispatch to be switched off.

like image 91
matt Avatar answered Apr 13 '26 13:04

matt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!