{"id":38011,"date":"2022-12-29T16:38:40","date_gmt":"2022-12-29T21:38:40","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=38011"},"modified":"2022-12-29T19:55:47","modified_gmt":"2022-12-30T00:55:47","slug":"its-often-memory-thats-killing-your-performance","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2022\/12\/29\/its-often-memory-thats-killing-your-performance\/","title":{"rendered":"It&rsquo;s Often Memory That&rsquo;s Killing Your Performance"},"content":{"rendered":"<p><a href=\"https:\/\/cocoaphony.micro.blog\/2022\/12\/28\/bigo-matters-but.html\">Rob Napier<\/a>:<\/p>\n<blockquote cite=\"https:\/\/cocoaphony.micro.blog\/2022\/12\/28\/bigo-matters-but.html\">\n<p>My first mistake was trying to make it parallel before I pulled out Instruments. Always start by profiling. Do not make systems parallel before you&rsquo;ve optimized them serially. Sure enough, the biggest bottleneck was random number generation.<\/p>\n<p>[&#8230;]<\/p>\n<p>Huge amounts of time were spent in retain\/release. Since there are no classes in this program, that might surprise you, but copy-on-write is implemented with internal classes, and that means ARC, and ARC means locks, and highly contended locks are the enemy of parallelism.<\/p>\n<p>[&#8230;]<\/p>\n<p>I rewrote <code>update<\/code> and all the other methods to take two integer parameters rather than one object parameter and cut my time down to 9 seconds [from 40].<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/mastodon.social\/@steve@discuss.systems\/109597329890043912\">Steve Canon<\/a>:<\/p>\n<blockquote cite=\"https:\/\/mastodon.social\/@steve@discuss.systems\/109597329890043912\">\n<p>pet peeve: using &ldquo;big-O&rdquo; to refer to abstract algorithmic complexity. Big-O is the technique of looking at the leading term and ignoring constant factors. It is usually the right tool to analyze memory use or cache misses as well!<\/p>\n<\/blockquote>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2022\/11\/29\/introduction-to-move-only-types-in-swift\/\">Introduction to Move-Only Types in Swift<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2022\/07\/01\/porting-graphing-calculator-from-c-to-swift\/\">Porting Graphing Calculator From C++ to Swift<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2021\/12\/23\/roadmap-for-improving-swift-performance-predictability\/\">Roadmap for Improving Swift Performance Predictability<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2016\/02\/03\/swift-optimization-tips-and-reference-counting\/\">Swift Optimization Tips and Reference Counting<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>Rob Napier: My first mistake was trying to make it parallel before I pulled out Instruments. Always start by profiling. Do not make systems parallel before you&rsquo;ve optimized them serially. Sure enough, the biggest bottleneck was random number generation. [&#8230;] Huge amounts of time were spent in retain\/release. Since there are no classes in this [&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":"2022-12-29T21:38:42Z","apple_news_api_id":"8aacd29a-1abe-4987-a626-af005da9a11b","apple_news_api_modified_at":"2022-12-30T00:55:51Z","apple_news_api_revision":"AAAAAAAAAAAAAAAAAAAAAw==","apple_news_api_share_url":"https:\/\/apple.news\/AiqzSmhq-SYemJq8AXamhGw","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":[55,263,138,71,901],"class_list":["post-38011","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-arc","tag-theory","tag-optimization","tag-programming","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/38011","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=38011"}],"version-history":[{"count":4,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/38011\/revisions"}],"predecessor-version":[{"id":38020,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/38011\/revisions\/38020"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=38011"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=38011"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=38011"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}