{"id":38496,"date":"2023-02-16T16:30:18","date_gmt":"2023-02-16T21:30:18","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=38496"},"modified":"2023-02-16T16:30:18","modified_gmt":"2023-02-16T21:30:18","slug":"using-order-files-to-speed-up-launches-and-conformance-checks","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2023\/02\/16\/using-order-files-to-speed-up-launches-and-conformance-checks\/","title":{"rendered":"Using Order Files to Speed Up Launches and Conformance Checks"},"content":{"rendered":"<p><a href=\"https:\/\/www.emergetools.com\/blog\/posts\/FasterAppStartupOrderFiles\">Noah Martin<\/a>:<\/p>\n<blockquote cite=\"https:\/\/www.emergetools.com\/blog\/posts\/FasterAppStartupOrderFiles\"><p>A 150MB+ app binary file, like the one in Uber&lsquo;s app, takes between 500 ms and 1 second just to be loaded into\nmemory (measured on an iPhone 6s). Loading large files like this is just a fraction of the app&lsquo;s launch time. To put\nin perspective, Apple&lsquo;s recommended startup time is just 400ms. That&lsquo;s already 1-2x the recommended completed\nlaunch time without any code even executing!<\/p><p>By default, apps can need to read more than 75% of their binary during startup. However, with the help of <strong>order files<\/strong>, we can read only the functions we need during start up.<\/p><p>[&#8230;]<\/p><p>The order file instructs the linker to put functions in a specific sequence. By ordering the binary so all the startup functions are together, we now only need to load those pages.<\/p><\/blockquote>\n\n<p><a href=\"https:\/\/www.emergetools.com\/blog\/posts\/how-order-files-speed-up-protocols\">Noah Martin<\/a>:<\/p><blockquote cite=\"https:\/\/www.emergetools.com\/blog\/posts\/how-order-files-speed-up-protocols\"><p>By default, protocol conformances end up spread throughout the <code>__TEXT\/__const<\/code> section of the binary.\nThis is because each module in an app generates their own static binary. When they are linked into the final app, the binaries are placed side by side.\nData from different modules is not interleaved in the executable.<\/p><p>[&#8230;]<\/p><p>We can apply the idea of using order files to group data onto as few pages as possible to conformances, and generate an order file that moves all conformances onto their own pages.<\/p><p>[&#8230;]<\/p><p>In our tests, co-locating the conformances like this resulted in an over 20% decrease in protocol conformance lookup time\non an iPhone 7 running iOS 15!<\/p><p>You can generate an order file that has this result by parsing the <a href=\"https:\/\/docs.emergetools.com\/docs\/linkmaps\">linkmap<\/a> file.<\/p><\/blockquote>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2023\/02\/08\/the-evolution-of-facebooks-ios-app-architecture\/\">The Evolution of Facebook&rsquo;s iOS App Architecture<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2021\/12\/31\/the-surprising-cost-of-protocol-conformances-in-swift\/\">The Surprising Cost of Checking Protocol Conformances in Swift<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2021\/06\/30\/faster-app-launching-in-ios-15-and-monterey\/\">Faster App Launching in iOS 15 and Monterey<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>Noah Martin: A 150MB+ app binary file, like the one in Uber&lsquo;s app, takes between 500 ms and 1 second just to be loaded into memory (measured on an iPhone 6s). Loading large files like this is just a fraction of the app&lsquo;s launch time. To put in perspective, Apple&lsquo;s recommended startup time is just [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2023-02-16T21:30:25Z","apple_news_api_id":"74deaf55-cf3a-4a35-9b06-44ba27067296","apple_news_api_modified_at":"2023-02-16T21:30:25Z","apple_news_api_revision":"AAAAAAAAAAD\/\/\/\/\/\/\/\/\/\/w==","apple_news_api_share_url":"https:\/\/apple.news\/AdN6vVc86SjWbBkS6JwZylg","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[205,31,2185,1274,30,2223,138,71,901,1441],"class_list":["post-38496","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-dyld","tag-ios","tag-ios-16","tag-lyft","tag-mac","tag-macos-13-ventura","tag-optimization","tag-programming","tag-swift-programming-language","tag-uber"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/38496","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=38496"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/38496\/revisions"}],"predecessor-version":[{"id":38497,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/38496\/revisions\/38497"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=38496"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=38496"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=38496"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}