<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Visual C++ Team Blog</title><link>http://blogs.msdn.com/b/vcblog/</link><description>All things Visual C++!</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>Deep Dive into NuGet Native (Part One)</title><link>http://blogs.msdn.com/b/vcblog/archive/2013/06/18/deep-dive-into-nuget-native-part-one.aspx</link><pubDate>Tue, 18 Jun 2013 18:38:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10421250</guid><dc:creator>Garrett Serack, MSFT</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/vcblog/rsscomments.aspx?WeblogPostID=10421250</wfw:commentRss><comments>http://blogs.msdn.com/b/vcblog/archive/2013/06/18/deep-dive-into-nuget-native-part-one.aspx#comments</comments><description>&lt;p&gt;Howdy!&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;Today I thought I&amp;rsquo;d start explaining how NuGet supports C/C++ packages under the covers, and look into how one could (theoretically) manually construct a package without using the CoApp PowerShell tools.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;As I mentioned before, C/C++ packages built for NuGet didn't require a whole lot of change in NuGet itself&amp;mdash;primarily because if we had made the Package Manager do all the complex work that was necessary to hook up a project, we&amp;rsquo;d be still implementing it all a year from now.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Instead we chose to add a fairly simple (and often requested) feature to NuGet, the ability to import MSBuild project file fragments into the consuming project. Previously, some package creators had hacked their way into something similar by including an &lt;strong&gt;&lt;strong&gt;&lt;code&gt;install.ps1&lt;/code&gt;&lt;/strong&gt;&lt;/strong&gt; PowerShell script in the package. While this sort of thing was workable, it opens up an awful can of worms.&amp;nbsp; As well, NuGet needed to support actually working on C++ project types and needed to shoe-horn in a new &amp;ldquo;framework type&amp;rdquo; that could represent native packages (which was simply called &lt;strong&gt;&lt;code&gt;native&lt;/code&gt;&lt;/strong&gt; ).&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;As of NuGet 2.5, when the package installs, it checks inside the &lt;strong&gt;&lt;code&gt;/build/&amp;lt;framework&amp;gt;&lt;/code&gt;&lt;/strong&gt; folder for files that are either called &lt;strong&gt;&lt;code&gt;&amp;lt;pkgName&amp;gt;.targets&lt;/code&gt;&lt;/strong&gt; or &lt;strong&gt;&lt;code&gt;&amp;lt;pkgName&amp;gt;.props&lt;/code&gt;&lt;/strong&gt; . If it finds a &lt;strong&gt;&lt;code&gt;.props&lt;/code&gt;&lt;/strong&gt;, it places an &lt;strong&gt;&lt;code&gt;&amp;lt;Import&amp;gt;&lt;/code&gt;&lt;/strong&gt; into the &lt;em&gt;top&lt;/em&gt; of the project file.&amp;nbsp; If it finds a &lt;strong&gt;&lt;code&gt;.targets&lt;/code&gt;&lt;/strong&gt; file, it places an &lt;strong&gt;&lt;code&gt;&amp;lt;Import&amp;gt;&lt;/code&gt;&lt;/strong&gt; into the &lt;em&gt;bottom&lt;/em&gt; of the project file.&amp;nbsp; This allows the package creator to have finer grained control as to when something is declared&amp;mdash;and if it can get overridden in the consuming project or not.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;At that point, NuGet&amp;rsquo;s involvement on how the package is integrated in the consuming project is pretty much complete. It&amp;rsquo;s now up to the package creator to craft the &lt;strong&gt;&lt;code&gt;.targets&lt;/code&gt;&lt;/strong&gt; and/or &lt;strong&gt;&lt;code&gt;.props&lt;/code&gt;&lt;/strong&gt; files in such a way enables the consuming project to effectively use the contents.&amp;nbsp;&lt;/p&gt;
&lt;h3&gt;The Simplest Package&lt;/h3&gt;
&lt;p&gt;Assume for a moment that we wanted to create a very simple package that contained only a single header file, and didn&amp;rsquo;t have any &lt;strong&gt;&lt;code&gt;.lib&lt;/code&gt;&lt;/strong&gt; files and didn&amp;rsquo;t have any redistributable files (ie, &lt;strong&gt;&lt;code&gt;.dll&lt;/code&gt;&lt;/strong&gt;&amp;nbsp; files).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Given a simple &lt;strong&gt;&lt;code&gt;mysample.h&lt;/code&gt;&lt;/strong&gt; file:&amp;nbsp;&lt;/p&gt;
&lt;pre style="background: #10100d; color: #a79a86; font-family: Consolas; border-radius: 5px;"&gt;&lt;br /&gt;#pragma&amp;nbsp;&lt;span style="color: #436c5c;"&gt;once&lt;/span&gt;
 
&lt;span style="color: #436c5c;"&gt;#include&lt;/span&gt;&amp;nbsp;&lt;span style="color: #44b1e3;"&gt;&amp;lt;stdio.h&amp;gt;&lt;/span&gt;
 
&lt;span style="color: #756f51;"&gt;/*&amp;nbsp;some&amp;nbsp;simple&amp;nbsp;function&amp;nbsp;*/&lt;/span&gt;
&lt;span style="color: #436c5c;"&gt;#define&lt;/span&gt;&amp;nbsp;&lt;span style="color: #e8e8e8;"&gt;SimpleWriteString&lt;/span&gt;&lt;span style="color: #80ff00;"&gt;(&lt;/span&gt;&amp;nbsp;&lt;span style="color: #e8e8e8;"&gt;str&lt;/span&gt;&amp;nbsp;&lt;span style="color: #80ff00;"&gt;)&lt;/span&gt;&amp;nbsp;&lt;span style="color: #e8e8e8;"&gt;printf&lt;/span&gt;&lt;span style="color: #80ff00;"&gt;(&lt;/span&gt;&amp;nbsp;&lt;span style="color: #e8e8e8;"&gt;str&lt;/span&gt;&amp;nbsp;&lt;span style="color: #80ff00;"&gt;)&lt;/span&gt;
&lt;br /&gt; &lt;/pre&gt;
&lt;p&gt;We then need to create the &lt;strong&gt;&lt;code&gt;mysample.targets&lt;/code&gt;&lt;/strong&gt; file that will ensure that we add the &lt;strong&gt;&lt;code&gt;include&lt;/code&gt;&lt;/strong&gt; directory into the consuming project.&lt;/p&gt;
&lt;pre style="background: #10100d; color: #a79a86; font-family: Consolas; border-radius: 5px;"&gt;&amp;nbsp;&lt;br /&gt;&lt;span style="color: #a1b070;"&gt;&amp;lt;?&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;xml&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #009b00;"&gt;version&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;=&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;"&lt;/span&gt;&lt;span style="color: #44b1e3;"&gt;1.0&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;"&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #009b00;"&gt;encoding&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;=&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;"&lt;/span&gt;&lt;span style="color: #44b1e3;"&gt;utf-8&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;"&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;?&amp;gt;&lt;/span&gt;
&lt;span style="color: #a1b070;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;Project&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #009b00;"&gt;ToolsVersion&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;=&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;"&lt;/span&gt;&lt;span style="color: #44b1e3;"&gt;4.0&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;"&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #009b00;"&gt;xmlns&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;=&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;"&lt;/span&gt;&lt;span style="color: #44b1e3;"&gt;http://schemas.microsoft.com/developer/msbuild/2003&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;"&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;nbsp;&amp;gt;&lt;/span&gt;
&lt;span style="color: #a1b070;"&gt;&amp;nbsp;&amp;nbsp;&amp;lt;&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;ItemDefinitionGroup&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #a1b070;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;ClCompile&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #a1b070;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;AdditionalIncludeDirectories&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #e8e8e8;"&gt;$(MSBuildThisFileDirectory)..\..\lib\native\include\;%(AdditionalIncludeDirectories)&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;AdditionalIncludeDirectories&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #a1b070;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;PreprocessorDefinitions&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #e8e8e8;"&gt;HAS_MYSAMPLE;%(PreprocessorDefinitions)&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;PreprocessorDefinitions&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #a1b070;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;ClCompile&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #a1b070;"&gt;&amp;nbsp;&amp;nbsp;&amp;lt;/&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;ItemDefinitionGroup&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #a1b070;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;Project&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;A very simple &lt;strong&gt;&lt;code&gt;mysample.nuspec&lt;/code&gt;&lt;/strong&gt; file (the .nuspec file is the manifest file used by NuGet to tell what is in the package. You can find more about the .nuspec file format from the &lt;a href="http://docs.nuget.org/docs/reference/nuspec-reference"&gt;docs on nuget.org&lt;/a&gt;&amp;nbsp;).&lt;/p&gt;
&lt;pre style="background: #10100d; border-radius: 5px; color: #a79a86; font-family: Consolas;"&gt;&lt;span style="color: #a1b070;"&gt;&lt;br /&gt;&amp;lt;?&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;xml&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #009b00;"&gt;version&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;=&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;"&lt;/span&gt;&lt;span style="color: #44b1e3;"&gt;1.0&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;"&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #009b00;"&gt;encoding&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;=&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;"&lt;/span&gt;&lt;span style="color: #44b1e3;"&gt;utf-8&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;"&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;?&amp;gt;&lt;/span&gt;
&lt;span style="color: #a1b070;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;package&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #a1b070;"&gt;&amp;nbsp;&amp;nbsp;&amp;lt;&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;metadata&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #a1b070;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;id&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #e8e8e8;"&gt;MySample&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;id&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #a1b070;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;version&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #e8e8e8;"&gt;1.2.3&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;version&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #a1b070;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;authors&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #e8e8e8;"&gt;Garrett&amp;nbsp;Serack&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;authors&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #a1b070;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;owners&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #e8e8e8;"&gt;CoApp&amp;nbsp;Project,&amp;nbsp;Garrett&amp;nbsp;Serack&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;owners&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #a1b070;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;requireLicenseAcceptance&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #e8e8e8;"&gt;false&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;requireLicenseAcceptance&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #a1b070;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;description&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #e8e8e8;"&gt;A&amp;nbsp;sample&amp;nbsp;library.&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;description&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #a1b070;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;releaseNotes&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #e8e8e8;"&gt;First&amp;nbsp;Release&amp;nbsp;of&amp;nbsp;MySample&amp;nbsp;library&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;releaseNotes&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #a1b070;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;copyright&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #e8e8e8;"&gt;Copyright&amp;nbsp;2013&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;copyright&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #a1b070;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;title&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #e8e8e8;"&gt;MySample&amp;nbsp;Library&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;title&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #a1b070;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;summary&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #e8e8e8;"&gt;A&amp;nbsp;sample&amp;nbsp;library&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;summary&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #a1b070;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;tags&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #e8e8e8;"&gt;native,&amp;nbsp;MySample&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;tags&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #a1b070;"&gt;&amp;nbsp;&amp;nbsp;&amp;lt;/&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;metadata&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #a1b070;"&gt;&amp;nbsp;&amp;nbsp;&amp;lt;&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;files&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #a1b070;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;file&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #009b00;"&gt;src&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;=&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;"&lt;/span&gt;&lt;span style="color: #44b1e3;"&gt;MySample.h&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;"&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #009b00;"&gt;target&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;=&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;"&lt;/span&gt;&lt;span style="color: #44b1e3;"&gt;\lib\native\include\mysample.h&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;"&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;nbsp;/&amp;gt;&lt;/span&gt;
&lt;span style="color: #a1b070;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;file&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #009b00;"&gt;src&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;=&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;"&lt;/span&gt;&lt;span style="color: #44b1e3;"&gt;mysample.targets&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;"&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #009b00;"&gt;target&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;=&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;"&lt;/span&gt;&lt;span style="color: #44b1e3;"&gt;\build\native\mysample.targets&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;"&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;nbsp;/&amp;gt;&lt;/span&gt;
&lt;span style="color: #a1b070;"&gt;&amp;nbsp;&amp;nbsp;&amp;lt;/&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;files&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #a1b070;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #d6d694;"&gt;package&lt;/span&gt;&lt;span style="color: #a1b070;"&gt;&amp;gt;&lt;br /&gt; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;Once we have those, it's fairly trivial to build the package with just the &lt;strong&gt;&lt;code&gt;NuGet&lt;/code&gt;&lt;/strong&gt; command-line tool:&lt;/p&gt;
&lt;pre style="background: #10100d; border-radius: 5px; color: #a79a86; font-family: Consolas;"&gt;&lt;span style="color: #e8e8e8;"&gt;&lt;br /&gt;c:\MySample\&amp;gt;&amp;nbsp;nuget&amp;nbsp;pack&lt;/span&gt;
 
&lt;span style="color: #e8e8e8;"&gt;Attempting&amp;nbsp;to&amp;nbsp;build&amp;nbsp;package&amp;nbsp;from&amp;nbsp;'MySample.nuspec'.&lt;/span&gt;
&lt;span style="color: #e8e8e8;"&gt;Successfully&amp;nbsp;created&amp;nbsp;package&amp;nbsp;'C:\MySample\MySample.1.2.3.nupkg'&lt;/span&gt;
&lt;br /&gt; &lt;/pre&gt;
&lt;p&gt;Of course if all libraries were this easy, we'd never needed to make a special tool to build packages for C++.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Next Time:&lt;/strong&gt; We'll dig into how we hook up .lib files to the linker, and making sure that redistributable files are copied to the output directory.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Also :&lt;/strong&gt;&amp;nbsp;In case you missed it, you might want to check out the &lt;a title="Channel 9 Interview on NuGet/C++" href="http://blogs.msdn.com/controlpanel/blogs/posteditor.aspx/channel9.msdn.com/Shows/C9-GoingNative/GoingNative-16-Garrett-Serak-Inside-NuGet-for-C"&gt;Channel 9 Interview on NuGet/C++&lt;/a&gt;.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10421250" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/vcblog/archive/tags/VS2010/">VS2010</category><category domain="http://blogs.msdn.com/b/vcblog/archive/tags/C_2B002B00_/">C++</category><category domain="http://blogs.msdn.com/b/vcblog/archive/tags/VS2012/">VS2012</category><category domain="http://blogs.msdn.com/b/vcblog/archive/tags/NuGet/">NuGet</category><category domain="http://blogs.msdn.com/b/vcblog/archive/tags/Libraries/">Libraries</category></item><item><title>Optimizing C++ Code : Overview</title><link>http://blogs.msdn.com/b/vcblog/archive/2013/06/12/optimizing-c-code-new-title.aspx</link><pubDate>Wed, 12 Jun 2013 20:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10425425</guid><dc:creator>Jim Hogg</dc:creator><slash:comments>13</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/vcblog/rsscomments.aspx?WeblogPostID=10425425</wfw:commentRss><comments>http://blogs.msdn.com/b/vcblog/archive/2013/06/12/optimizing-c-code-new-title.aspx#comments</comments><description>&lt;p&gt;If you have arrived in the middle of this blog series, you might want instead to begin at the &lt;a href="http://blogs.msdn.com/b/vcblog/archive/2013/05/29/optimizing-c-code.aspx"&gt;beginning&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;This post explains the flow of data within the Visual C++ compiler &amp;ndash; starting with our C++ source program, and ending with a corresponding binary program. This post is&amp;nbsp;an easy one &amp;ndash; dipping our toes into the shallow end of ocean.&lt;/p&gt;
&lt;p&gt;Let's examine what happens when we compile a single-file program, stored in &lt;span style="font-family: Consolas; font-size: 9pt; background-color: #f2f2f2;"&gt;App.cpp&lt;/span&gt;, from the command-line. (If you were to launch the compilation from within Visual Studio, the diagram below would have to include higher layers of software; however, these end up emitting the very commands I'm about to describe).&lt;/p&gt;
&lt;p&gt;So let's imagine we just typed: &lt;span style="font-family: Consolas; font-size: 9pt; background-color: #f2f2f2;"&gt;CL /O2 App.cpp&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;The &lt;span style="font-family: Consolas; font-size: 9pt; background-color: #f2f2f2;"&gt;CL&lt;/span&gt; stands from "Compile and Link". &lt;span style="font-family: Consolas; font-size: 9pt; background-color: #f2f2f2;"&gt;/O2&lt;/span&gt; tells the compiler to optimize for speed &amp;ndash; to generate machine code that runs as fast as possible. This command launches a process to execute the &lt;span style="font-family: Consolas; font-size: 9pt; background-color: #f2f2f2;"&gt;CL.EXE&lt;/span&gt; program &amp;ndash; a "driver" that calls several pieces of software: when joined together, they process the text in our &lt;span style="font-family: Consolas; font-size: 9pt; background-color: #f2f2f2;"&gt;App.cpp&lt;/span&gt; and eventually generate a binary file, called &lt;span style="font-family: Consolas; font-size: 9pt; background-color: #f2f2f2;"&gt;App.exe&lt;/span&gt;. When executed, this binary will carry out the operations we specified in our original source file.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-65-69-metablogapi/1727.061213_5F00_1742_5F00_OptimizingC1.png" alt="" /&gt;&lt;/p&gt;
&lt;p&gt;Let's take a stroll around the diagram above and explain what's going on.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Consolas; font-size: 9pt; background-color: #f2f2f2;"&gt;CL.EXE&lt;/span&gt; parses our command-line, and checks that it makes sense. It then calls the C++ "front-end", located in &lt;span style="font-family: Consolas; font-size: 9pt; background-color: #f2f2f2;"&gt;C1XX.DLL&lt;/span&gt; (the "CXX" is meant to suggest "C++", but dates back to a time when "+" was not a legal character in file names). The &lt;span style="font-family: Consolas; font-size: 9pt; background-color: #f2f2f2;"&gt;FrontEnd&lt;/span&gt; is the part of the chain that &lt;em&gt;understands &lt;/em&gt;the C++ language. It scans, parses and transforms your &lt;span style="font-family: Consolas; font-size: 9pt; background-color: #f2f2f2;"&gt;App.cpp&lt;/span&gt; into an equivalent tree, passed to the next component via 5 temporary files. The "language" represented by these 5 files is called "CIL", for "C Intermediate Language". Don't confuse this with the intermediate code, generated by managed languages such as C#, sometimes called "MSIL" but also, unfortunately, named "CIL" in the &lt;a href="http://www.ecma-international.org/publications/standards/Ecma-335.htm"&gt;ECMA-335&lt;/a&gt; standard.&lt;/p&gt;
&lt;p&gt;Next, &lt;span style="font-family: Consolas; font-size: 9pt; background-color: #f2f2f2;"&gt;CL.EXE&lt;/span&gt; calls the "back-end", located in &lt;span style="font-family: Consolas; font-size: 9pt; background-color: #f2f2f2;"&gt;C2.DLL&lt;/span&gt;. We call the BackEnd "UTC", which stands for "Universal Tuple Compiler", although this name doesn't show up in any of the binaries included into Visual Studio. The BackEnd starts by converting the information from the FrontEnd into tuples &amp;ndash; a binary stream of instructions. If we were to display them, they would look like a kind of high-level assembly language. It's high-level in the senses that:&lt;/p&gt;
&lt;ul style="margin-left: 38pt;"&gt;
&lt;li&gt;Operations are generic. For example, a &lt;span style="font-family: Consolas; font-size: 9pt; background-color: #f2f2f2;"&gt;BRANCH(LE)&lt;/span&gt; instruction versus how it will eventually be translated, into a &lt;span style="font-family: Consolas; font-size: 9pt; background-color: #f2f2f2;"&gt;cmp&lt;/span&gt; instruction in x64 machine code&lt;/li&gt;
&lt;li&gt;Operands are symbolic. For example, &lt;span style="font-family: Consolas; font-size: 9pt; background-color: #f2f2f2;"&gt;t66&lt;/span&gt; denoting a temporary variable generated by the compiler, versus &lt;span style="font-family: Consolas; font-size: 9pt; background-color: #f2f2f2;"&gt;eax&lt;/span&gt;, the x64 register that will hold its value at runtime&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Because we asked the compiler to optimize for speed, via the &lt;span style="font-family: Consolas; font-size: 9pt; background-color: #f2f2f2;"&gt;/O2&lt;/span&gt; switch, the Optimize part of the BackEnd analyses the tuples and transforms them into a form that will execute faster but that is semantically equivalent &amp;ndash; that yields the same results as would the original tuples. After this step, the tuples are passed to the CodeGen part of the BackEnd, which decides the final binary code to emit.&lt;/p&gt;
&lt;p&gt;The CodeGen module emits &lt;span style="font-family: Consolas; font-size: 9pt; background-color: #f2f2f2;"&gt;App.obj&lt;/span&gt; as a file on disk. Finally, the Linker consumes that file, resolves any references to libraries, and produces the final &lt;span style="font-family: Consolas; font-size: 9pt; background-color: #f2f2f2;"&gt;App.exe&lt;/span&gt; binary.&lt;/p&gt;
&lt;p&gt;In the diagram, black arrows show flow of data &amp;ndash; text or binary. &lt;span style="color: red;"&gt;Red&lt;/span&gt; arrows show flow of control.&lt;/p&gt;
&lt;p&gt;(We shall return to this diagram later in the series, when we hit the topic of Whole Program Optimization, specified to the compiler with the &lt;span style="font-family: Consolas; font-size: 9pt; background-color: #f2f2f2;"&gt;/GL&lt;/span&gt; switch, and to the Linker with the &lt;span style="font-family: Consolas; font-size: 9pt; background-color: #f2f2f2;"&gt;/LTCG&lt;/span&gt; switch. We will see the same set of boxes, but connected in different ways)&lt;/p&gt;
&lt;p&gt;In summary:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The &lt;span style="font-family: Consolas; font-size: 9pt; background-color: #f2f2f2;"&gt;FrontEnd&lt;/span&gt; &lt;em&gt;understands&lt;/em&gt; C++ source code. Other parts of the chain &amp;ndash; BackEnd and Linker &amp;ndash; are (mostly) isolated from the details of the original source language. They work upon the tuples, mentioned above, that form a kind of high-level, binary assembly language. The original source program might have been any imperative language, such as FORTRAN or Pascal. The BackEnd really doesn't care. Well, not much.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The &lt;span style="font-family: Consolas; font-size: 9pt; background-color: #f2f2f2;"&gt;Optimize&lt;/span&gt; part of the BackEnd transforms tuples into more efficient forms that will run faster. Such transformations, we call optimizations. (We should really call them "improvements", because there may be &lt;em&gt;other&lt;/em&gt; improvements that produce even faster-running code &amp;ndash; we just aim to get close to that ideal. However, someone coined the term "optimization" a few decades ago, and we're stuck with it) There are dozens of such optimizations, with names like "constant folding", "common sub-expression elimination", "hoisting", "invariant code motion", "dead code elimination", "function inlining", "auto vectorization", etc. For the most part, these optimizations are independent of the eventual processor on which the program will execute &amp;ndash; they are "machine-independent" optimizations.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The &lt;span style="font-family: Consolas; font-size: 9pt; background-color: #f2f2f2;"&gt;CodeGen&lt;/span&gt; part of the Backend decides how to lay out the runtime stack (used to implement function "activation frames"); how to make best use of the available machine registers; adds details that implement function calling conventions; and transforms the code to make it run even faster, using its detailed knowledge of the target machine. (As one tiny example, if you ever look at assembly code &amp;ndash; for example, using the Disassembly window in Visual Studio (Alt+8) whilst debugging code &amp;ndash; you may notice instructions like &lt;span style="font-family: Consolas; font-size: 9pt; background-color: #f2f2f2;"&gt;xor eax, eax&lt;/span&gt; used to set EAX to zero, in preference to the more obvious &lt;span style="font-family: Consolas; font-size: 9pt; background-color: #f2f2f2;"&gt;move eax,0&lt;/span&gt;. Why? Because the XOR form is smaller (2 bytes instead of 5) and executes faster. We might well call this a "micro-optimization", and wonder whether it's worth the bother. Recall the proverb: "Look after the pennies and the pounds will look after themselves"). In contrast to the &lt;span style="font-family: Consolas; font-size: 9pt; background-color: #f2f2f2;"&gt;Optimize&lt;/span&gt; part, &lt;span style="font-family: Consolas; font-size: 9pt; background-color: #f2f2f2;"&gt;CodeGen&lt;/span&gt; is aware of the processor architecture on which the code is going to run.&amp;nbsp; In some cases, it will even change the order in which machine instructions are laid out &amp;ndash; a process called "scheduling" &amp;ndash; based upon its understanding of the target processor.&amp;nbsp;&amp;nbsp; Oh, I'd better explain that a bit more: &lt;span style="font-family: Consolas; font-size: 9pt; background-color: #f2f2f2;"&gt;CodeGen&lt;/span&gt; &lt;em&gt;knows&lt;/em&gt; whether it is targeting x86 or x64 or ARM-32; but it's rare that is can&amp;nbsp;&lt;em&gt;know&lt;/em&gt; the specific micro-architecture the code will run on - Nehalem versus Sandy Bridge, for example. (see the /favor:ATOM switch for a case where it knows more detail)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This blog will focus on the &lt;span style="font-family: Consolas; font-size: 9pt; background-color: #f2f2f2;"&gt;Optimize&lt;/span&gt; part of the compiler, with scant mention of the other components that make up the chain &amp;ndash; &lt;span style="font-family: Consolas; font-size: 9pt; background-color: #f2f2f2;"&gt;FrontEnd&lt;/span&gt;, &lt;span style="font-family: Consolas; font-size: 9pt; background-color: #f2f2f2;"&gt;CodeGen&lt;/span&gt; or &lt;span style="font-family: Consolas; font-size: 9pt; background-color: #f2f2f2;"&gt;Linker&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;This post has introduced lots of jargon. I'm not intending that you make total sense of it all at this point: this post is an overview, sprinkled with ideas that hopefully pique your interest, and ensure you'll come back next time, where I will start to explain all of that jargon.&lt;/p&gt;
&lt;p&gt;Next time, we will look at perhaps the simplest optimization and how it works &amp;ndash; the one called "constant folding".&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10425425" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/vcblog/archive/tags/VC_2B002B00_/">VC++</category><category domain="http://blogs.msdn.com/b/vcblog/archive/tags/performance/">performance</category></item><item><title>C++ REST SDK 1.0.0 is now available </title><link>http://blogs.msdn.com/b/vcblog/archive/2013/06/04/c-rest-sdk-1-0-0-is-now-available.aspx</link><pubDate>Tue, 04 Jun 2013 18:11:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10423584</guid><dc:creator>Sana Mithani</dc:creator><slash:comments>9</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/vcblog/rsscomments.aspx?WeblogPostID=10423584</wfw:commentRss><comments>http://blogs.msdn.com/b/vcblog/archive/2013/06/04/c-rest-sdk-1-0-0-is-now-available.aspx#comments</comments><description>&lt;p&gt;&lt;span style="color: #000000; font-family: verdana,geneva; font-size: small;"&gt;&lt;span style="text-decoration: underline;"&gt;&lt;a href="http://blogs.msdn.com/b/vcblog/archive/2013/02/26/the-c-rest-sdk-quot-casablanca-quot.aspx"&gt;&lt;span style="color: #000000; text-decoration: underline;"&gt;Since our last release&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;, the C++ REST SDK team has been working on improving the overall quality of the SDK to transition out of the beta phase.&amp;nbsp; We are excited to announce that the C++ REST SDK has reached release quality and that v1.0.0 is now available for download! W&lt;span style="mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;"&gt;ith the recent &lt;span style="text-decoration: underline;"&gt;&lt;a href="http://blogs.msdn.com/b/vcblog/archive/2013/04/26/nuget-for-c.aspx"&gt;&lt;span style="color: #000000; text-decoration: underline;"&gt;NuGet support for C++ projects&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;, &lt;/span&gt;&lt;span style="mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;"&gt;we&amp;rsquo;ve also decided to also release the C++ REST SDK as a NuGet package&lt;/span&gt;. You can now download the SDK directly into Visual Studio through the NuGet package manager. This release stabilizes several APIs and fixes multiple customer-reported issues.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #000000; font-family: verdana,geneva; font-size: small;"&gt;Please visit us on &lt;span style="background-color: #ffffff;"&gt;&lt;span style="text-decoration: underline;"&gt;&lt;a href="http://casablanca.codeplex.com/"&gt;&lt;span style="color: #000000; text-decoration: underline; background-color: #ffffff;"&gt;CodePlex&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&amp;nbsp;to&lt;/span&gt; learn more about the C++ REST SDK, explore the source code, and download the latest release.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #000000; font-family: verdana,geneva; font-size: small;"&gt;Thank you for your continued support and encouragement. We would love to hear your feedback and feature requests for our upcoming releases. Please take a few minutes to fill out this &lt;span style="text-decoration: underline;"&gt;&lt;strong&gt;&lt;a href="http://www.instant.ly/s/WcE1w"&gt;&lt;span style="color: #000000; text-decoration: underline;"&gt;survey&lt;/span&gt;&lt;/a&gt;&lt;/strong&gt;&lt;/span&gt; and share your thoughts. We will share the results on CodePlex next week.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10423584" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/vcblog/archive/tags/casablanca/">casablanca</category><category domain="http://blogs.msdn.com/b/vcblog/archive/tags/JSON/">JSON</category><category domain="http://blogs.msdn.com/b/vcblog/archive/tags/C_2B002B00_+REST+SDK/">C++ REST SDK</category></item><item><title>Optimizing C++ Code</title><link>http://blogs.msdn.com/b/vcblog/archive/2013/05/29/optimizing-c-code.aspx</link><pubDate>Wed, 29 May 2013 20:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10421814</guid><dc:creator>Jim Hogg</dc:creator><slash:comments>23</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/vcblog/rsscomments.aspx?WeblogPostID=10421814</wfw:commentRss><comments>http://blogs.msdn.com/b/vcblog/archive/2013/05/29/optimizing-c-code.aspx#comments</comments><description>&lt;h1&gt;Introduction&lt;/h1&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;In this series of blog posts, I will explain some of the optimizations that make your code run faster. I'll include&amp;nbsp;examples, with&amp;nbsp;measurements of how much gain various optimizations might deliver. I'll then describe some of the more recent optimizations that the team has added, transforming your code in amazing, non-obvious ways.&lt;/p&gt;
&lt;p&gt;Who 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 "what the original C++ code says". 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.&lt;/p&gt;
&lt;p&gt;What 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 &amp;ndash; such as "de-virtualization"). 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 &amp;ndash; I'll aim to provide insights without digging all the way down to the binary machine code that the compiler generates.&lt;/p&gt;
&lt;p&gt;I will create a Table-of-Contents here for all of the blog posts in this series, updating as I publish each post.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/b/vcblog/archive/2013/05/29/optimizing-c-code.aspx"&gt;Introduction&lt;/a&gt; (this post)&lt;/li&gt;
&lt;li&gt;Overview &amp;ndash; the process of compiling C++ code&lt;/li&gt;
&lt;li&gt;Constant-Folding&lt;/li&gt;
&lt;li&gt;Dead Code Elimination&lt;/li&gt;
&lt;li&gt;. . .&lt;/li&gt;
&lt;li&gt;. . .&lt;/li&gt;
&lt;li&gt;Function Inlining&lt;/li&gt;
&lt;li&gt;. . .&lt;/li&gt;
&lt;li&gt;. . .&lt;/li&gt;
&lt;li&gt;Whole-Program Optimization (Link-Time Code Generation)&lt;/li&gt;
&lt;li&gt;. . .&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10421814" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/vcblog/archive/tags/VC_2B002B00_/">VC++</category><category domain="http://blogs.msdn.com/b/vcblog/archive/tags/performance/">performance</category></item><item><title>Profile Guided Optimization (PGO) – Under the Hood</title><link>http://blogs.msdn.com/b/vcblog/archive/2013/05/28/profile-guided-optimization-pgo-under-the-hood.aspx</link><pubDate>Tue, 28 May 2013 06:59:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10421671</guid><dc:creator>Ankit Asthana</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/vcblog/rsscomments.aspx?WeblogPostID=10421671</wfw:commentRss><comments>http://blogs.msdn.com/b/vcblog/archive/2013/05/28/profile-guided-optimization-pgo-under-the-hood.aspx#comments</comments><description>&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: times new roman,times;"&gt;To introduce myself I am &lt;a title="mailto:aasthan@microsoft.com" href="http://blogs.msdn.com/controlpanel/blogs/posteditor.aspx/Ankit Asthana"&gt;Ankit Asthana&lt;/a&gt; and I am the program manager for the backend C++ compiler. In my &lt;a href="http://blogs.msdn.com/b/vcblog/archive/2013/04/08/profile-guided-optimization-pgo.aspx"&gt;last few blogs&lt;/a&gt; I provided an introduction to what PGO is all about along with case studies which covered how &lt;a href="http://msdn.microsoft.com/en-us/library/vstudio/e7k32f4k.aspx"&gt;Profile Guided Optimization (PGO)&lt;/a&gt; is used to make real world applications such as &lt;a href="http://blogs.msdn.com/b/vcblog/archive/2013/05/08/speeding-up-php-performance-for-your-application-using-profile-guided-optimization-pgo.aspx"&gt;SAP NetWeaver&lt;/a&gt; and &lt;a href="http://blogs.msdn.com/b/vcblog/archive/2013/05/08/speeding-up-php-performance-for-your-application-using-profile-guided-optimization-pgo.aspx"&gt;Windows PHP faster&lt;/a&gt;. &lt;/span&gt;&lt;span style="font-family: times new roman,times;"&gt;In this blog I would like to talk about how PGO works under the hood and helps produce faster code. So let us take a look at how PGO helps the compiler backend in building an optimized version of an application. Once we know how PGO optimizations work, we can understand how PGO makes applications faster. So let's get started!&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h1&gt;How does PGO help build leaner and faster native applications?&lt;/h1&gt;
&lt;p&gt;&lt;span style="font-family: Times New Roman; font-size: small;"&gt;Carrying on from my&lt;a href="http://blogs.msdn.com/b/vcblog/archive/2013/04/04/how-to-build-faster-and-high-performing-native-applications-using-pgo.aspx"&gt; first&lt;/a&gt; blog let us take a look at the following code snippets again:&lt;br /&gt;&lt;br /&gt;&lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-65-69-metablogapi/2766.052813_5F00_0703_5F00_ProfileGuid1.png" alt="" /&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Times New Roman; font-size: small;"&gt;To recall, PGO helps optimize the application by leveraging profile data collected from running performance centric user scenarios. PGO'izing an application requires three basic steps &lt;strong&gt;(Instrument, Train and Optimize)&lt;/strong&gt;. Instrumenting an application means building with special compiler/link flags which insert probes into the generated code. These probes then when hit during the training phase collect data providing information on which branch was taken in the &lt;strong&gt;whichBranchIsTaken&lt;/strong&gt; code snippet or what is the usual value of &lt;strong&gt;*p in the devirtualization&lt;/strong&gt; code snippet as an example. This data collected by probes in the training phase is dumped into a database file &lt;strong&gt;*.pgd&lt;/strong&gt; which is then supplied to the compiler as an input for the optimize phase of PGO. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Times New Roman; font-size: small;"&gt;During the optimize phase of PGO, the data collected in the database file is used as an input for a list of optimizations (table 1, below). Although the database file is used as an input for many optimizations, inlining and layout based PGO optimizations provide majority of the performance gains so let us take a look at how the training data collected helps in better inlining and layout based decisions.&lt;/span&gt;&lt;/p&gt;
&lt;table style="border-collapse: collapse;" border="0"&gt;&lt;colgroup&gt;&lt;col style="width: 208px;" /&gt;&lt;col style="width: 208px;" /&gt;&lt;col style="width: 208px;" /&gt;&lt;/colgroup&gt;
&lt;tbody valign="top"&gt;
&lt;tr style="background: white;"&gt;
&lt;td style="padding-left: 7px; padding-right: 7px; border-top: none; border-bottom: solid #c9c9c9 1.5pt; border-right: none;"&gt;&amp;nbsp;&lt;/td&gt;
&lt;td style="padding-left: 7px; padding-right: 7px; border-top: none; border-left: none; border-bottom: solid #c9c9c9 1.5pt; border-right: none;"&gt;&amp;nbsp;&lt;/td&gt;
&lt;td style="padding-left: 7px; padding-right: 7px; border-top: none; border-left: none; border-bottom: solid #c9c9c9 1.5pt;"&gt;&amp;nbsp;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height: 25px; background: #ededed;"&gt;
&lt;td style="padding-left: 7px; padding-right: 7px; border-top: none; border-bottom: solid #c9c9c9 0.25pt; border-right: solid #c9c9c9 0.25pt;"&gt;
&lt;p&gt;&lt;span style="font-family: Times New Roman; font-size: 10pt;"&gt;Full and Partial Inlining&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td style="padding-left: 7px; padding-right: 7px; border-top: none; border-left: none; border-bottom: solid #c9c9c9 0.25pt; border-right: solid #c9c9c9 0.25pt;"&gt;
&lt;p&gt;&lt;span style="font-family: Times New Roman; font-size: 10pt;"&gt;Function Layout&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td style="padding-left: 7px; padding-right: 7px; border-top: none; border-left: none; border-bottom: solid #c9c9c9 0.25pt;"&gt;
&lt;p&gt;&lt;span style="font-family: Times New Roman; font-size: 10pt;"&gt;Speed and Size decision&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height: 27px;"&gt;
&lt;td style="padding-left: 7px; padding-right: 7px; border-top: none; border-bottom: solid #c9c9c9 0.25pt; border-right: solid #c9c9c9 0.25pt;"&gt;
&lt;p&gt;&lt;span style="font-family: Times New Roman; font-size: 10pt;"&gt;Basic Block Layout&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td style="padding-left: 7px; padding-right: 7px; border-top: none; border-left: none; border-bottom: solid #c9c9c9 0.25pt; border-right: solid #c9c9c9 0.25pt;"&gt;
&lt;p&gt;&lt;span style="font-family: Times New Roman; font-size: 10pt;"&gt;Code Separation&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td style="padding-left: 7px; padding-right: 7px; border-top: none; border-left: none; border-bottom: solid #c9c9c9 0.25pt;"&gt;
&lt;p&gt;&lt;span style="font-family: Times New Roman; font-size: 10pt;"&gt;Virtual Call Expansion&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="height: 24px; background: #ededed;"&gt;
&lt;td style="padding-left: 7px; padding-right: 7px; border-top: none; border-bottom: solid #c9c9c9 0.25pt; border-right: solid #c9c9c9 0.25pt;"&gt;
&lt;p&gt;&lt;span style="font-family: Times New Roman; font-size: 10pt;"&gt;Switch Expansion&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td style="padding-left: 7px; padding-right: 7px; border-top: none; border-left: none; border-bottom: solid #c9c9c9 0.25pt; border-right: solid #c9c9c9 0.25pt;"&gt;
&lt;p&gt;&lt;span style="font-family: Times New Roman; font-size: 10pt;"&gt;Data Separation&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td style="padding-left: 7px; padding-right: 7px; border-top: none; border-left: none; border-bottom: solid #c9c9c9 0.25pt;"&gt;
&lt;p&gt;&lt;span style="font-family: Times New Roman; font-size: 10pt;"&gt;Loop Unrolling&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p style="margin-left: 72pt;"&gt;&lt;strong&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Table 1:&lt;/strong&gt;&amp;nbsp;Some optimizations gaining from PGO&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: times new roman,times; font-size: small;"&gt;Inlining decisions for PGO are based upon call graph path profiling. Simply put, the basic mantra behind using call graph path profiling for inlining decisions is to understand the behavior of a function being called from a specific call path. This is important as the behavior of a function call from one-call path may be drastically different from another call path. Having information on which call path is hotter helps in better inlining decisions as the optimizer only inlines frequent call paths hence minimizing the code bloat due to inlining but still gaining performance by inlining hotter call paths. Take a look at the example given below:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-65-69-metablogapi/4403.052813_5F00_0703_5F00_ProfileGuid2.png" alt="" /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Figure 1a: Sequence of calls to function 'bar' from 'goo', 'foo' and 'bat' &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: 10pt;"&gt;&lt;span style="font-family: times new roman,times; font-size: small;"&gt;Example depicted in figure 1a above illustrates function calls being made to function 'bar' from function 'goo', 'foo' and 'bat'. The number on the edge denotes how many times function 'bar' is called from function 'goo', 'foo' and 'bat' respectively. So the edge from function 'goo' to function 'bar' denotes that function 'bar' was called 10 times from function 'goo' for a given PGO training session. Now call graph path profiling is all about finding out the behavior of a function call from a specific call path. So figure 1a will be further broken down into figure 1b.&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Times New Roman; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-65-69-metablogapi/5482.052813_5F00_0703_5F00_ProfileGuid3.png" alt="" /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; Figure 1b: Sequence of calls to function 'bar' from 'goo', 'foo' and 'bat'&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Sequence of calls to function 'baz' from 'bar'&lt;br /&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Times New Roman; font-size: small;"&gt;Analyzing figure 1b it becomes obvious that the major benefit will come from inlining function 'bar' into 'bat' given the higher frequency 'i.e. 100' of calls made from 'bat' to 'bar'. Additionally it also is somewhat obvious that the other major advantage will come from inlining 'baz' into 'bar' given the high frequency of calls made to function 'baz' from call paths 'goo-bar' and 'foo-bar'. The impact of pgo-inlining for the above scenario is shown below in figure 1c. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Times New Roman; font-size: 10pt;"&gt;.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-65-69-metablogapi/2287.052813_5F00_0703_5F00_ProfileGuid4.png" alt="" /&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: Times New Roman; font-size: 8pt;"&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Figure 1c: Impact of PGO inlining, 'bar' is inlined into 'bat' and 'baz' is inlined into 'bar'. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Times New Roman; font-size: 10pt;"&gt;Inlining decisions are made before layout, speed vs size decisions and all other optimizations. Now from my &lt;a href="http://blogs.msdn.com/b/vcblog/archive/2013/04/08/profile-guided-optimization-pgo.aspx"&gt;last blog&lt;/a&gt;, let us recall the output (figure 2) of an optimized PGO build. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: times new roman,times; font-size: small;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-65-69/7266.pgo2.jpg"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-65-69/7266.pgo2.jpg" alt="" border="0" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: times new roman,times; font-size: small;"&gt;&amp;nbsp;'Speed vs. Size' decisions are based on post-inliner dynamic instruction count. Code segments (i.e. functions) with higher dynamic instruction count are optimized for speed whereas code segments with lower dynamic instruction counts are optimized for size. In the build output shown in figure 2 above &lt;span style="color: #1e1e1e;"&gt;&lt;span style="background-color: white;"&gt;&lt;strong&gt;6 of 3619 (0.17%) profiled functions will be compiled for speed, and the rest of the functions will be compiled for size &lt;/strong&gt;is a result of this decision ma&lt;/span&gt;king process. The speed and size decisions are followed by &lt;strong&gt;'Block Layout'&lt;/strong&gt; and &lt;strong&gt;'Live and Scenario dead code separation'&lt;/strong&gt; optimization. Basic blocks are ordered so that most frequent paths fall through (figure 3). Live and Scenario dead code separation is performed to minimize working set and improve code locality. Code (functions/blocks) which are scenario dead (i.e. not exercised in the training scenario) are placed in a special section (figure 4). &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-65-69-metablogapi/1651.052813_5F00_0703_5F00_ProfileGuid7.png" alt="" /&gt;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-65-69-metablogapi/1541.052813_5F00_0703_5F00_ProfileGuid8.png" alt="" align="left" /&gt;&lt;/p&gt;
&lt;p style="padding-left: 120px;"&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left: 30px;"&gt;&lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-65-69-metablogapi/2146.052813_5F00_0703_5F00_ProfileGuid9.png" alt="" /&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;span style="color: #1e1e1e; font-family: Times New Roman; font-size: 10pt;"&gt;&lt;span style="font-size: small;"&gt;&lt;span style="background-color: white;"&gt;Finally, based on the post-inliner and post-code-separation, call graph profile data function layout is performed. Only functions in the live sections are laid out. Dead blocks are not included. The overall strategy behind function layout is that functions which are strongly connected (calling each other with high frequency) are put together. A call is supposed to have achieve page locality if the callee is located in the same page. Take a look at the example in figure&lt;/span&gt; 6 below:&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;img src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-65-69-metablogapi/6862.052813_5F00_0703_5F00_ProfileGuid10.png" alt="" /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;strong&gt;Figure 6:&lt;/strong&gt; Function layout based upon call graph and profile data&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;span style="font-family: times new roman,times; font-size: small;"&gt;Some other optimizations that are performed based upon the training data are switch case expansion and virtual call speculation. The switch case expansion optimization uses the most common value of the switch expression that PGO collects and pulls it out of the switch construct. Take a look at how the code snippet presented at the start of this blog will be optimized using the PGO data when switch case expansion optimization is performed.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-65-69/4353.switch.png"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-65-69/4353.switch.png" alt="" border="0" /&gt;&lt;/a&gt;&lt;span style="background: white; font-family: 'Times New Roman','serif'; font-size: 10pt; mso-fareast-font-family: 'Times New Roman'; mso-fareast-theme-font: minor-fareast; mso-highlight: white; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;"&gt;&lt;br /&gt;&lt;br /&gt;Similarly, if a virtual call, &lt;/span&gt;&lt;span style="font-family: 'Times New Roman','serif'; font-size: 10pt; mso-fareast-font-family: 'Times New Roman'; mso-fareast-theme-font: minor-fareast; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;"&gt;or other call through a function pointer, frequently targets a certain function, profile-guided optimization can insert a conditionally-executed direct call to the frequently-targeted function, and the direct call can be inlined.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h1&gt;Wrap up&lt;/h1&gt;
&lt;p&gt;Although Profile Guided Optimization (PGO) is a complex technology, this blog should provide you folks an idea on the usefulness of profile guided optimization and how PGO works under the hood to make plethora of products more performant. In my future blogs I will try to cover a best practices guide which covers common pitfalls and highlights some tips and tricks for PGO users. So stay tuned! Additionally, if you would like us to blog about some other PGO-related scenarios please let us know.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10421671" width="1" height="1"&gt;</description></item><item><title>New Channel 9 video on the Visual Studio 3D Starter Kit now online</title><link>http://blogs.msdn.com/b/vcblog/archive/2013/05/24/new-channel-9-video-on-the-visual-studio-3d-starter-kit-now-online.aspx</link><pubDate>Fri, 24 May 2013 17:50:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10421225</guid><dc:creator>Jennifer Leaf [MSFT]</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/vcblog/rsscomments.aspx?WeblogPostID=10421225</wfw:commentRss><comments>http://blogs.msdn.com/b/vcblog/archive/2013/05/24/new-channel-9-video-on-the-visual-studio-3d-starter-kit-now-online.aspx#comments</comments><description>&lt;p&gt;If you&amp;rsquo;re interested in DirectX development, head on over to Channel 9, where there&amp;rsquo;s &lt;a href="http://channel9.msdn.com/posts/Creating-the-Virtual-Experiment-Laboratory-app-with-the-Visual-Studio-3D-Starter-Kit"&gt;a new video about the Visual Studio 3D Starter Kit&lt;/a&gt;.&amp;nbsp; This time, Roberto Sonnino interviews Gokhan Sengun, who&amp;rsquo;s created the Virtual Experiment Laboratory app, which is the first known app on the Windows Store that was built using the Starter Kit - at least, that wasn&amp;rsquo;t built by a Microsoft employee.&amp;nbsp; :)&amp;nbsp; Gohkan shares some tips on using the Starter Kit, and also some great demos of the Visual Studio Shader Designer.&lt;br /&gt;&amp;nbsp;&lt;br /&gt;To learn more about the Visual Studio 3D Starter Kit, check out our previous &lt;a href="http://blogs.msdn.com/b/vcblog/archive/2013/02/13/visual-studio-3d-starter-kit-now-for-windows-phone-8.aspx"&gt;introduction to the Starter Kit&lt;/a&gt;, the 3-part series on the Visual C++ blog and the accompanying video (&lt;a href="http://blogs.msdn.com/b/vcblog/archive/2013/03/26/developing-an-app-with-the-visual-studio-3d-starter-kit-part-1-of-3.aspx"&gt;part 1&lt;/a&gt;, &lt;a href="http://blogs.msdn.com/b/vcblog/archive/2013/04/02/developing-an-app-with-the-visual-studio-3d-starter-kit-part-2-of-3.aspx"&gt;part 2&lt;/a&gt;, &lt;a href="http://blogs.msdn.com/b/vcblog/archive/2013/04/11/developing-an-app-with-the-visual-studio-3d-starter-kit-part-3-of-3.aspx"&gt;part 3&lt;/a&gt;, &lt;a href="http://channel9.msdn.com/posts/VS-3D-Starter-Kit-Dice-Roller"&gt;Channel9 video&lt;/a&gt;), or just &lt;a href="http://aka.ms/vs3dkit"&gt;download the Starter Kit&lt;/a&gt; directly.&lt;br /&gt;&amp;nbsp;&lt;br /&gt;If you&amp;rsquo;re working on an app using the Starter Kit, we&amp;rsquo;d love to hear from you.&amp;nbsp; Leave us a note in the comments!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10421225" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/vcblog/archive/tags/DirectX/">DirectX</category><category domain="http://blogs.msdn.com/b/vcblog/archive/tags/Graphics/">Graphics</category><category domain="http://blogs.msdn.com/b/vcblog/archive/tags/C_2B002B00_/">C++</category><category domain="http://blogs.msdn.com/b/vcblog/archive/tags/windows+8/">windows 8</category><category domain="http://blogs.msdn.com/b/vcblog/archive/tags/Windows+Store+Apps/">Windows Store Apps</category><category domain="http://blogs.msdn.com/b/vcblog/archive/tags/3D+Starter+Kit/">3D Starter Kit</category><category domain="http://blogs.msdn.com/b/vcblog/archive/tags/VS2012/">VS2012</category></item><item><title>Image Processing with C++ AMP and the .NET Framework</title><link>http://blogs.msdn.com/b/vcblog/archive/2013/05/21/image-processing-with-c-amp-and-the-net-framework.aspx</link><pubDate>Tue, 21 May 2013 16:28:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10420156</guid><dc:creator>Eric Battalio</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/vcblog/rsscomments.aspx?WeblogPostID=10420156</wfw:commentRss><comments>http://blogs.msdn.com/b/vcblog/archive/2013/05/21/image-processing-with-c-amp-and-the-net-framework.aspx#comments</comments><description>&lt;p&gt;Image processing is a computational task that lends itself very well to GPU compute scenarios. In many cases the most commonly used algorithms are inherently massively parallel, with each pixel in the image being processed independently from the others. As a result, image processing toolkits have been early adopters of the new GPGPU programming model. Many of these mass-market toolkits, however, can be more accurately described as &lt;em&gt;image manipulation&lt;/em&gt; packages that offer "image-in, image-out" capabilities; in other words, for each operation there is an input image and a resulting output (manipulated) image. In contrast, an &lt;em&gt;image processing&lt;/em&gt; workflow differs from this in that the goal is usually the portrayal or extraction of analytical information which is determined after some multi-step processing workflow. These workflows are commonly employed in scientific and technical industries like medical imaging.&lt;/p&gt;
&lt;p&gt;For the last two years, Core Optical Inc. has been building an image processing toolkit for the .NET framework called &lt;a href="http://www.coreoptical.com/"&gt;PrecisionImage.NET&lt;/a&gt;. Internally it centers around two separate execution branches, one targeting multicore CPUs and the other targeting GPU execution. While the CPU branch is a fully-managed CLS-compliant implementation leaning heavily on the .NET framework's excellent built-in thread pool, the GPU branch is implemented using Microsoft's brand new C++ AMP compiler.&lt;/p&gt;
&lt;p&gt;We had two requirements when choosing the GPGPU tool we would use for that branch of our toolkit. First, the generated code needed to be vendor agnostic so that a decision to use our SDK wouldn't overly restrict our customer's choice concerning graphics hardware. The current minimum platform for C++ AMP is DirectX 11, a version that will soon be ubiquitous among modern GPUs from Intel, Nvidia and AMD. Secondly, since we focus on the Microsoft developer stack we needed something that would play nicely with the .NET framework. Obviously C++ AMP is the best bet in this regard since it's produced by Microsoft.&lt;/p&gt;
&lt;p&gt;For a v1 product we've found C++ AMP to be both solid and easy to program to. Although Microsoft doesn't produce an official managed wrapper, accessing AMP in .NET was a straight forward matter of P/Invoking from our existing C# code base. To keep the surface area between the two to a minimum, we stuck with our managed code for the CPU fallback and condensed the various operations of the SDK into hundreds of compact AMP kernels compiled in combinations of single/double precision and 32/64-bit implementations. In almost all cases we found the simpler untiled model readily met our speedup goals. When this wasn't the case, we were able to produce a tiled version that met our performance objectives with minimum drama.&lt;/p&gt;
&lt;p&gt;To demonstrate the performance of the GPU branch we decided to &lt;a href="http://coreoptical.wordpress.com/"&gt;compare the speed&lt;/a&gt; of two operations running on a 6-core CPU (multithreaded managed code) versus the C++ AMP version running on two different GPUs from Nvidia. The first operation was chosen as an ideal case for GPU implementation and consisted of a 2D convolution using a large kernel implemented using AMP's simple untiled model. The second was chosen as for its unsuitability to GPU processing and was implemented using the tiled model. Even when including the overhead of marshalling arguments from managed to native code, and memory copying to/from the GPU, we saw huge gains (60x) in the first test case. Perhaps more surprising were the gains achieved in the second, less suitable, test case &amp;ndash; up to 7x &amp;ndash; an indication of the quality of the AMP compiler. Based on our experience to date, if you are a developer considering using AMP from a managed code base we can recommend it without reservation.&lt;/p&gt;
&lt;p&gt;Currently, one aspect of C++ AMP imposes a performance limitation (acknowledged by Microsoft) for our particular use cases: redundant memory copying between CPU and GPU. This is partly imposed by hardware and partly by software. Since our SDK is designed to allow the easy assembly of processing chains, the overhead of these redundant memory copies can add up quickly. Microsoft has stated that this behavior needs improvement, and all our AMP kernels are using the &lt;em&gt;array_view&lt;/em&gt; abstraction to take advantage of the improvement when it arrives. This will be a welcome enhancement to the AMP implementation, especially given AMD's recent announcement of their hUMA architecture initiative. With both the hardware and software pieces falling into place soon, we should see a whole new generation of image processing software with unprecedented power and flexibility.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10420156" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/vcblog/archive/tags/C_2B002B00_/">C++</category><category domain="http://blogs.msdn.com/b/vcblog/archive/tags/AMP/">AMP</category></item><item><title>Speed up Windows PHP Performance using Profile Guided Optimization (PGO) </title><link>http://blogs.msdn.com/b/vcblog/archive/2013/05/08/speeding-up-php-performance-for-your-application-using-profile-guided-optimization-pgo.aspx</link><pubDate>Wed, 08 May 2013 17:38:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10415236</guid><dc:creator>Ankit Asthana</dc:creator><slash:comments>6</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/vcblog/rsscomments.aspx?WeblogPostID=10415236</wfw:commentRss><comments>http://blogs.msdn.com/b/vcblog/archive/2013/05/08/speeding-up-php-performance-for-your-application-using-profile-guided-optimization-pgo.aspx#comments</comments><description>&lt;p&gt;To introduce myself I am &lt;a href="mailto:aasthan@microsoft.com"&gt;Ankit Asthana&lt;/a&gt; and I am the program manager for the backend C++ compiler. In my last two blogs I provided an introduction to what &lt;a href="http://msdn.microsoft.com/en-us/library/e7k32f4k(v=vs.80).aspx"&gt;Profile Guided Optimization (PGO&lt;/a&gt;) is all about and a &lt;a href="http://blogs.msdn.com/b/vcblog/archive/2013/04/22/profile-guided-optimization-drives-next-generation-sap-netweaver-performance.aspx"&gt;case study&lt;/a&gt; which illustrates how PGO is used to make &lt;strong&gt;SAP NetWeaver&lt;/strong&gt; faster.&amp;nbsp; In this blog I would like to present the story about how PGO is used make official &lt;a href="http://windows.php.net/"&gt;Windows PHP&lt;/a&gt; binaries faster. &lt;strong&gt;Stephen Zarkos &lt;/strong&gt;&lt;strong&gt;(&lt;/strong&gt;&lt;em&gt;Program Manager for Windows PHP&lt;/em&gt;&lt;strong&gt;)&lt;/strong&gt; has been kind enough for providing the content for this blog.&lt;br /&gt; &lt;br /&gt; &amp;nbsp;After reading this blog you folks should be able to further understand and use this case study to introduce PGO for your applications. In addition to this, for experienced PHP users, this blog post &lt;strong&gt;should serve as an optimization opportunity&lt;/strong&gt; to further optimize Windows PHP performance for their specific workloads. So let's get started! &lt;br /&gt; &lt;br /&gt; As most of you probably already know PHP is a server side scripting language designed for web development but also used as a general purpose programming language. PHP is heavily used today and it powers millions of websites and webservers. In addition to this PHP is also used to power a plethora of open source content management system (CMS) such as Joomla, WordPress and Drupal. &lt;br /&gt; &lt;br /&gt; The effort to PGO'ize the Windows PHP binaries was led by &lt;strong&gt;Microsoft Open Source Technology (OSTC) group&lt;/strong&gt;. OSTC's primary goal is to work with open-source communities to help their software interoperate with or run better on Windows Server and Windows Azure. To be precise, this is not the only group at Microsoft that works with open source but amazingly these days is only one of many. A few examples of projects this group works on are PHP on Windows, Openstack with Hyper-V, CoApp (coapp.org) and the Linux Integration Services for Hyper-V and Azure. &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;Why Windows-PHP team used Profile Guided Optimization (PGO)?&lt;/h2&gt;
&lt;p&gt;Over the past several years, Microsoft and its partners have worked diligently with the PHP community to improve the experience PHP developers and users have on&amp;nbsp;&lt;a href="http://php.iis.net/" target="_blank"&gt;Windows Server&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://www.windowsazure.com/en-us/develop/php/" target="_blank"&gt;Windows Azure&lt;/a&gt;. As a result newer versions of PHP (i.e. PHP 5.4) for Windows include dramatic improvements that come from a deep collaboration between the PHP Core Maintainers and Microsoft. One factor attributing to a faster &lt;strong&gt;Windows PHP 5.4 and 5.5&lt;/strong&gt; is &lt;strong&gt;Profile Guided Optimization (PGO)&lt;/strong&gt;. The overall goal with this collaboration is to improve PHP on Windows and enable Windows specific capabilities in a way that provides PHP users the same (or better, if possible) capabilities that they see on other platforms.&lt;br /&gt; &lt;br /&gt; After having tested the water with using &lt;strong&gt;PGO for Windows PHP 5.3&lt;/strong&gt;, the team was finally able to incorporate PGO for &lt;strong&gt;Windows PHP 5.4&lt;/strong&gt;. Performance is a primary goal for the Windows PHP team which served as the key reason behind PGO'izing the PHP binaries on Windows. PGO provided an important opportunity to optimize the performance of the PHP interpreter without changing any functional behavior.&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;What are the 'key steps' performed by the Windows PHP team for PGO'izing Windows PHP binaries?&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/h2&gt;
&lt;p&gt;Revisiting my previous blogs, there are essentially three steps required in PGO'izing an application (Instrument, Train and Optimize). Remember the 'Instrument' and 'Optimize' steps require an &lt;a href="http://msdn.microsoft.com/en-us/library/xbf3tbeh.aspx"&gt;&lt;strong&gt;'LTCG:PGINSTRUMENT'&lt;/strong&gt;&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/xbf3tbeh.aspx"&gt;'&lt;strong&gt;LTCG:PGOPTIMIZE&lt;/strong&gt;'&lt;/a&gt; build respectively (for more information please take a look at my last &lt;a href="http://blogs.msdn.com/b/vcblog/archive/2013/04/04/how-to-build-faster-and-high-performing-native-applications-using-pgo.aspx"&gt;&lt;span&gt;blog&lt;/span&gt;&lt;/a&gt;&amp;nbsp;post).&lt;/p&gt;
&lt;p&gt;The steps to PGO'ize Windows PHP binaries are essentially in-line with PGO'izing any generic application and are as follows:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Creating an Instrumented build of Windows PHP binaries (i.e. the Instrumentation Phase)&lt;br /&gt; &lt;/strong&gt;&lt;br /&gt; For those of you who would like to get some firsthand experience in doing this, creating an instrumented version of the Windows PHP binaries requires user to pass the additional '&lt;strong&gt;--enable-pgi&lt;/strong&gt;' parameter to the PHP &lt;em&gt;configure&lt;/em&gt; script. After running the &lt;em&gt;configure&lt;/em&gt; script just rebuild with &lt;strong&gt;&lt;em&gt;'nmake snap'&lt;/em&gt;&lt;/strong&gt;. For more detailed instructions on how to set this up take a look at this &lt;a href="http://www.ksingla.net/2010/05/php-pgo-build-for-maximum-performance-on-windows/"&gt;blog post&lt;/a&gt;.&lt;br /&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Collecting Training Data (i.e. the Train Phase)&lt;br /&gt; &lt;/strong&gt;&lt;br /&gt; This step can be as simple as setting up PHP with IIS or Apache with your PHP application and then accessing the application via a web-browser. A good training session should exercise workflows that your users will hit most often. The Windows PHP team currently trains by having a number of PHP applications preconfigured, for both IIS and Apache (on Windows) and then exercising these applications via requesting specific pages (usually several times for the most used pages) in order to get wide coverage. As of today, the Windows PHP team trains with every snapshot and release build of PHP binaries.&lt;br /&gt; &lt;br /&gt; Snapshot builds can happen multiple times a day (depending on the number of commits on that particular day).&amp;nbsp; Every snapshot for PHP 5.4, 5.5 and the Master branch is automated where the build automation goes through the process of creating the instrumented binary, setting up IIS and Apache, running through a series of applications to produce the training data, copying those back to the PHP build directory and then finally rebuilding the optimized PHP.&lt;br /&gt; &lt;br /&gt; The end result of the training phase is the "*.pgc" files which are essentially training data files that contain all the information required by the 'Optimize phase'. You need to copy these files back into your PHP build directory for the next phase of the build.&lt;br /&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Building optimized Windows PHP binaries (i.e. the Optimize Phase) &lt;br /&gt; &lt;br /&gt; &lt;/strong&gt;&lt;strong&gt;A user can build an optimized version of PHP binaries &lt;/strong&gt;following the simple steps listed below:&lt;br /&gt; a. Copy the *.pgc files back to your PHP build directory&lt;br /&gt; b. Run the command "nmake --clean-pgo" to clean your build directory (but not the .pgc files)&lt;br /&gt; c. Re-run the configure script, but remove the "--enable-pgi" parameter and instead add the "--with-pgo" parameter&lt;br /&gt; d. Run "nmake" and then "nmake snap" to build the final optimized PHP&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This entire process can take several hours, depending upon the speed of your build machine. For best results (i.e higher build throughput and maximum PGO performance gains), use Visual Studio 2012 RTM.&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;What were the 'key challenges' faced by the Windows PHP team while PGO'izing Windows PHP binaries?&lt;/h2&gt;
&lt;p&gt;The work for PGO'izing PHP began as a proof of concept exercise. The Windows PHP team did some work several years ago to test PGO and see how they can leverage it for PHP. This exercise was useful in finding the following &lt;strong&gt;few key challenges&lt;/strong&gt; which the team addressed when enabling PGO for PHP 5.4:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;How to train the PHP binaries:&lt;/strong&gt; At first it was difficult for the Windows PHP team to understand how best to train the PHP Windows binaries. In particular, 'what training scenarios to run?', 'how long to train for?' and 'what kind of applications to train with?'&lt;br /&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Absorbing longer build times: &lt;/strong&gt;To save man hours, every part of the 'Windows PHP PGO build process was automated. Adding PGO to the build process was a fairly easy exercise, but the main challenge here was to deal with the additional build times required. Given the Windows PHP has various builds (thread-safe, non-thread, and now x86 &amp;amp; x64 for PHP 5.5) to absorb the additional build times they needed to add more/faster build systems, and improve their build automation to support concurrent builds&lt;strong&gt;.&lt;br /&gt;&amp;nbsp;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Additional quality assurance required: &lt;/strong&gt;Validating the effectiveness of your PGO training scenario is essential and plays a major part in obtaining maximum performance gains. Good testing is still the key to the success of PGO in PHP.&amp;nbsp; At the time PHP 5.4 was released the Windows PHP team had pretty good test automation and hence were able to identify issues where using PGO changed the behavior of PHP.&amp;nbsp; These issues observed were then mitigated by the use of #pragma statements.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;What are the performance gains received by the Windows PHP team by PGO'izing their binaries?&lt;/h2&gt;
&lt;p&gt;For testing PHP performance, applications such as Drupal, Mediawiki, Wordpress and Joomla are deployed on IIS and Apache webservers. These applications are then stressed using load agents and various metrics such as &lt;strong&gt;transactions per second (TPS)&lt;/strong&gt; are recorded and reported. To better demonstrate the performance improvements we can see with PGO, the 'TPS' for these applications with/without PGO'ized PHP binaries is listed in the table below: &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-65-69/5684.PerformanceGains.png"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-65-69/5684.PerformanceGains.png" alt="" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;em&gt;Table 1: Performance gain for applications leveraging PGO'ized Windows PHP 5.5 &lt;/em&gt;&lt;/p&gt;
&lt;p&gt;As you can see some of these results are pretty &lt;strong&gt;impressive&lt;/strong&gt;! A detailed summary of these results which includes some of the gritty details used to generate these results can be found &lt;strong&gt;&lt;a href="http://windows.php.net/downloads/snaps/ostc/pftt/perf/results-20130430-5.5.0beta4-5.5.0beta4nonPGO-1246.html"&gt;here&lt;/a&gt;&lt;/strong&gt;&lt;strong&gt;.&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;&lt;span style="font-size: 1.5em;"&gt;Wrap up&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;Although Profile Guided Optimization (PGO) is a complex technology, I hope this blog provides you further evidence on the usefulness of PGO and does a fair job in explaining how the Windows PHP team PGO'ized the Windows PHP binaries. In my future blogs I will go over how PGO works under the hood to provide the performance gains enjoyed by a plethora of products out there.&lt;/p&gt;
&lt;p&gt;So stay tuned! Additionally, if you would like us to blog about some other PGO-related scenarios or are just curios and have a few more questions about PGO please feel free to reach out to &lt;a href="mailto:aasthan@microsoft.com"&gt;me&lt;/a&gt;. I will do my best to answer them.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10415236" width="1" height="1"&gt;</description></item><item><title>NuGet for C++ and the Northwest Hackathon</title><link>http://blogs.msdn.com/b/vcblog/archive/2013/05/08/nuget-for-c-and-the-northwest-hackathon.aspx</link><pubDate>Wed, 08 May 2013 17:16:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10416445</guid><dc:creator>Garrett Serack, MSFT</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/vcblog/rsscomments.aspx?WeblogPostID=10416445</wfw:commentRss><comments>http://blogs.msdn.com/b/vcblog/archive/2013/05/08/nuget-for-c-and-the-northwest-hackathon.aspx#comments</comments><description>&lt;p&gt;Howdy!&lt;/p&gt;
&lt;p&gt;My name is&amp;nbsp;&lt;a href="http://blogs.msdn.com/b/garretts/"&gt;Garrett Serack&lt;/a&gt;, I'm not actually part of the Visual C++ team--I actually work as a Senior Software Development Engineer in Microsoft's Open Source Technology Center, which is part of Windows Server. I have a distinctly different job than most here at Microsoft-I work to get Open Source software running better on Windows and Azure.&lt;/p&gt;
&lt;p&gt;A&amp;nbsp;&lt;a href="http://blogs.msdn.com/b/vcblog/archive/2013/04/26/nuget-for-c.aspx"&gt;little over a week ago&lt;/a&gt;, I released the beta version of the&amp;nbsp;&lt;a href="http://coapp.org/news/2013-04-26-Announcing-CoApp-Tools-For-NuGet.html"&gt;CoApp PowerShell tools&lt;/a&gt;&amp;nbsp;that let us generate &lt;a href="http://blogs.msdn.com/controlpanel/blogs/posteditor.aspx/http::/nuget.org"&gt;NuGet &lt;/a&gt;packages for C and C++ libraries.&lt;/p&gt;
&lt;p&gt;Over the next few weeks, I'll try to explain what the heck goes on under the covers when creating packages for Visual C++, how you can exploit all of the power of Visual Studio in C/C++ packages and in the process, explore what it would take to manually create packages without the tools.&lt;/p&gt;
&lt;p&gt;Today however, I'm here for a slightly different purpose: We're having an&amp;nbsp;&lt;a href="http://coapp.org/news/2013-05-06-Northwest-Hackathon.html"&gt;Open Source "Hackathon"&lt;/a&gt;&amp;nbsp;here on campus this Friday and Saturday (&lt;strong&gt;May 10th and 11th&lt;/strong&gt;), and I'm offering the opportunity for anyone interested in building C/C++ packages with NuGet to come on out, learn, code and have a good time. I'll be on hand all day and into the evening Friday and Saturday hacking away, and helping out anyone who's interested.&lt;/p&gt;
&lt;p&gt;Also, folks from the the NuGet team itself will be around, so if you have questions for them, you know where they will be!&lt;/p&gt;
&lt;p&gt;We're gonna have a ton of&amp;nbsp;&lt;strong&gt;food&lt;/strong&gt;,&amp;nbsp;&lt;strong&gt;prizes&lt;/strong&gt;,&amp;nbsp;&lt;strong&gt;drinks&lt;/strong&gt;, and a lot of fun. If you're into Open Source, and are in the area, I'd love to have you come out, hang around and write some code!&lt;/p&gt;
&lt;h3&gt;&lt;span style="font-size: medium;"&gt;&lt;strong&gt;&lt;a href="http://coapp.org/news/2013-05-06-Northwest-Hackathon.html"&gt;Don't forget to register!&lt;/a&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/h3&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10416445" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/vcblog/archive/tags/NuGet+OpenSource/">NuGet OpenSource</category></item><item><title>Fix: Visual Studio 2012 Update 2 breaks Windows XP targeting with ATL and/or statically linking MFC</title><link>http://blogs.msdn.com/b/vcblog/archive/2013/05/07/fix-visual-studio-2012-update-2-breaks-windows-xp-targeting-with-atl-and-or-statically-linking-mfc.aspx</link><pubDate>Tue, 07 May 2013 22:25:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10416816</guid><dc:creator>Eric Battalio</dc:creator><slash:comments>31</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/vcblog/rsscomments.aspx?WeblogPostID=10416816</wfw:commentRss><comments>http://blogs.msdn.com/b/vcblog/archive/2013/05/07/fix-visual-studio-2012-update-2-breaks-windows-xp-targeting-with-atl-and-or-statically-linking-mfc.aspx#comments</comments><description>&lt;p&gt;Recently, some of our customers reported a bug in Visual Studio 2012 Update 2 that breaks Windows XP targeting with C++ in some scenarios. Specifically, applications using ATL and/or statically linking with MFC will get the following error when run on Windows XP:&lt;/p&gt;
&lt;p style="margin-left: 36pt;"&gt;"The procedure entry point InitializeCriticalSectionEx could not be located in the dynamic link library kernel32.dll."&lt;/p&gt;
&lt;p&gt;This issue has been fixed in &lt;a href="http://go.microsoft.com/fwlink/?LinkID=290979" target="_blank"&gt;Visual Studio 2012 Update 3 RC1&lt;/a&gt;. If you encounter this issue, please download and install this update.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10416816" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/vcblog/archive/tags/Announcements/">Announcements</category></item></channel></rss>