Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Optimizing work in iOS runtime

Sign upSign InSign upSign InBorisFollowITNEXT--ListenShareThere are a sufficient number of ways to increase the speed of a project at runtime. Let’s look at the most popular of them:Under the hood, any new class will use dynamic (table) dispatch. This is a price for the ability to be inherited, but if the class is not inherited, you can save a significant amount of resources. The final prefix will turn your class into a statically dispatched object.Before optimization:After optimization:Examples of speed boost:A similar approach is used for class methods, but there are several options available:Both prefixes will turn your method into a statically dispatched method, but with different scopes.Before optimization:After optimization:Examples of speed boost:One of the most curious and rarely used types of optimization. Inline optimization allows you to copy code calculations directly to the place where a given function is called without calling a method marked with inline, which reduces the number of method calls and works faster than static dispatch.Among the pitfalls, in order to force the compiler to call a method with inline optimization — it is necessary to mark the method not only @inlineable but also @inline(__always)It is important not to mark methods that spend a large amount of resources on copying with these prefixes; there is a risk of filling the cache of all processor levels with calculations of these methods and, as a result, getting slower instead of speeding up.Before optimization:After optimization:Examples of speed boost:Under the hood, protocols in Swift can be implemented for Reference Types and value types. Due to the fact that the memory management mechanism for reference types and value types are different, you can significantly speed up the compiler by limiting protocols adoption to reference types only.Before optimization:After optimization:Examples of speed boost:Array was originally intended not only as a collection type for Swift, allowing elements of the same type to be stored sequentially, but also as a collection type providing compatibility with NSArray.In case the array is intended to store non-ObjC data types, it is recommended to use ContagiousArray for more efficient operation of the array.Before optimization:After optimization:Examples of speed boost:Don’t hesitate to contact me on Twitter if you have any questions. Also, you can always buy me a coffee.----ITNEXTSenior iOS Developer | Founder of Flow: Diary, Calendar, Gallery | #ObjC | #Swift | #UIKit | #SwiftUIBorisinBetter Programming--Jacob FerusinITNEXT--8Juntao QiuinITNEXT--14Boris--2brenno--2Artem Kvasnetskyi--Amisha IinCanopas--Computer Science DiariesinDev Genius--Henri Bredt--Jim Lai--4HelpStatusAboutCareersBlogPrivacyTermsText to speechTeams



This post first appeared on VedVyas Articles, please read the originial post: here

Share the post

Optimizing work in iOS runtime

×

Subscribe to Vedvyas Articles

Get updates delivered right to your inbox!

Thank you for your subscription

×