{"id":1493,"date":"2013-05-29T13:00:00","date_gmt":"2013-05-29T13:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/vcblog\/2013\/05\/29\/optimizing-c-code\/"},"modified":"2019-02-18T18:41:05","modified_gmt":"2019-02-18T18:41:05","slug":"optimizing-c-code","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/optimizing-c-code\/","title":{"rendered":"Optimizing C++ Code"},"content":{"rendered":"<p>Hi, my name is Jim Hogg and I am a Program Manager, working in the Visual C++ compiler team in Microsoft, based on the main campus here in Redmond. More specifically, I work in the part of the compiler that optimizes your code, to make it run faster, or to make it smaller, or a mixture of the two.\nIn this series of blog posts, I will explain some of the optimizations that make your code run faster. I&#8217;ll include\u00a0examples, with\u00a0measurements of how much gain various optimizations might deliver. I&#8217;ll then describe some of the more recent optimizations that the team has added, transforming your code in amazing, non-obvious ways.\nWho is this blog aimed at? Anyone that is interested in how compilers work. Anyone that wonders how a compiler can possibly make the code you wrote run faster than &#8220;what the original C++ code says&#8221;. And, on the opposite side, some of the patterns that prevent or inhibit optimization: armed with this knowledge, you might tweak your source code to allow the optimizer more freedom, and make your program run faster.\nWhat are the pre-requisites to follow along with this blog? Some knowledge of programming in C or C++. (Most of the examples I will use can be understood in C. Only towards the end will I examine optimizations that are specific to C++ code \u2013 such as &#8220;de-virtualization&#8221;). Ideally, you should be able to read 64-bit assembler code: that way, you can really see the transformations the optimizations make. But this is not a hard requirement \u2013 I&#8217;ll aim to provide insights without digging all the way down to the binary machine code that the compiler generates.\nI will create a Table-of-Contents here for all of the blog posts in this series, updating as I publish each post.<\/p>\n<ol>\n<li><a href=\"http:\/\/blogs.msdn.com\/b\/vcblog\/archive\/2013\/05\/29\/optimizing-c-code.aspx\">Introduction<\/a> (this post)<\/li>\n<li><a href=\"http:\/\/blogs.msdn.com\/b\/vcblog\/archive\/2013\/06\/12\/optimizing-c-code-new-title.aspx\">Overview<\/a> \u2013 the process of compiling C++ code<\/li>\n<li><a href=\"http:\/\/blogs.msdn.com\/b\/vcblog\/archive\/2013\/07\/04\/optimizing-c-code-constant-folding.aspx\">Constant-Folding<\/a><\/li>\n<li><a href=\"http:\/\/blogs.msdn.com\/b\/vcblog\/archive\/2013\/08\/09\/optimizing-c-code-dead-code-elimination.aspx\">Dead Code Elimination<\/a><\/li>\n<li>. . .<\/li>\n<li>. . .<\/li>\n<li>Function Inlining<\/li>\n<li>. . .<\/li>\n<li>. . .<\/li>\n<li>Whole-Program Optimization (Link-Time Code Generation)<\/li>\n<li>. . .<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi, my name is Jim Hogg and I am a Program Manager, working in the Visual C++ compiler team in Microsoft, based on the main campus here in Redmond. More specifically, I work in the part of the compiler that optimizes your code, to make it run faster, or to make it smaller, or a [&hellip;]<\/p>\n","protected":false},"author":271,"featured_media":35994,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[66,36],"class_list":["post-1493","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cplusplus","tag-performance","tag-vc"],"acf":[],"blog_post_summary":"<p>Hi, my name is Jim Hogg and I am a Program Manager, working in the Visual C++ compiler team in Microsoft, based on the main campus here in Redmond. More specifically, I work in the part of the compiler that optimizes your code, to make it run faster, or to make it smaller, or a [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/1493","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/users\/271"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/comments?post=1493"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/1493\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media\/35994"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media?parent=1493"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=1493"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=1493"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}