<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://port25.technet.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>Port 25: The Open Source Community at Microsoft : Garrett Serack, Interop</title><link>http://port25.technet.com/archive/tags/Garrett+Serack/Interop/default.aspx</link><description>Tags: Garrett Serack, Interop</description><dc:language>en</dc:language><generator>CommunityServer 2007.1 (Build: 40109.1145)</generator><item><title>Crafting a Better PHP Build Process on Windows – Part IV</title><link>http://port25.technet.com/archive/2009/06/23/crafting-a-better-php-build-process-on-windows-part-iv.aspx</link><pubDate>Wed, 24 Jun 2009 00:12:00 GMT</pubDate><guid isPermaLink="false">af7480c4-26b7-468d-87b0-2acebabb473d:26365</guid><dc:creator>Garrett Serack</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://port25.technet.com/rsscomments.aspx?PostID=26365</wfw:commentRss><comments>http://port25.technet.com/archive/2009/06/23/crafting-a-better-php-build-process-on-windows-part-iv.aspx#comments</comments><description>&lt;P&gt;&lt;EM&gt;In&amp;nbsp;the &lt;A class="" href="http://port25.technet.com/archive/2009/06/17/crafting-a-better-php-build-process-on-windows-part-iii.aspx" target=_blank mce_href="http://port25.technet.com/archive/2009/06/17/crafting-a-better-php-build-process-on-windows-part-iii.aspx"&gt;previous&amp;nbsp;post&lt;/A&gt;, I discussed what it took to use PGO on the Windows PHP build. That led to me building automated build scripts...&lt;/EM&gt;&lt;/P&gt;
&lt;H5&gt;&lt;U&gt;Automation as the root of all evil &lt;/U&gt;&lt;/H5&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;EM&gt;"Anything that can be done for you, automatically, can be done to you, automatically." - David C. Wyland&lt;/EM&gt; &lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;First, I had to get the entire dependency stack into the mix.&amp;nbsp;While some of the dependent libraries had VCProject files, some didn't.&amp;nbsp;Worse, even if they had them, you couldn't tell with a degree of certainty that they were compiled with the same settings which would enable them to take advantage of PGO optimization.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I began taking each project, updating (or creating, using the &lt;A class="" href="http://gstoolkit.codeplex.com/Wiki/View.aspx?title=Trace" target=_blank mce_href="http://gstoolkit.codeplex.com/Wiki/View.aspx?title=Trace"&gt;Trace&lt;/A&gt; and &lt;A class="" href="http://gstoolkit.codeplex.com/Wiki/View.aspx?title=mkProject" target=_blank mce_href="http://gstoolkit.codeplex.com/Wiki/View.aspx?title=mkProject"&gt;mkProject&lt;/A&gt; tools) the Visual C++ project files that would use the same settings as the rest, and eventually came up with a solution file that had 74 projects in it - some of the projects generated more than one binary. &lt;/P&gt;
&lt;P&gt;Next, I had to actually automate the process of creating the vcproject files. Once you've got the right dependencies, the PHP build process cranks out over 30 binaries when you include the PHP extensions that get built as part of the core.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;After what seemed like a million compile-verify-tweak iterations, I had the tools that could generate VCProject files for the core PHP and all the extensions, provided it was all in the right place. &lt;/P&gt;
&lt;P&gt;Next I wrote a .cmd batch script that went step-by-step, checking out the source, compiling the dependent libraries, building the PHP makefile, compiling PHP like the community did - and logging what it was doing, then switching to instrumentation, rebuilding the dependencies again, building the stack, PGO training it with test data and some applications (Wordpress, MediaWiki and phpBB) and then relinking it with optimization. &lt;/P&gt;
&lt;P&gt;I got the .cmd script almost working, but it was fairly fragile.&amp;nbsp; At that point I &lt;A class="" href="http://fearthecowboy.com/post/Choosing-a-batch-scripting-language-on-Windows.aspx" target=_blank mce_href="http://fearthecowboy.com/post/Choosing-a-batch-scripting-language-on-Windows.aspx"&gt;decided to switch batch scripting strategies&lt;/A&gt;&amp;nbsp;and, in about a week, rewrote the batch script in &lt;A class="" href="http://fearthecowboy.com/?tag=/jscript" target=_blank mce_href="http://fearthecowboy.com/?tag=/jscript"&gt;JScript&lt;/A&gt;, which was far more flexible, and a lot more reliable. &lt;/P&gt;
&lt;H5&gt;&lt;U&gt;What's next... &lt;/U&gt;&lt;/H5&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;EM&gt;"The future always arrives too fast... and in the wrong order." - Alvin Toffler &lt;/EM&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;During this process, I tweaked the build process that is generated quite a bit, adding in a few more applications to the PGO training, which cranks the performance up more and more. &lt;/P&gt;
&lt;P&gt;Now, I can add in more scripts to assist with the training pretty trivially, but it still takes some effort to package up an entire application like MediaWiki or Wordpress and include it into the build process.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;Even once I've added in an application, I end up doing a whole slew of comparative testing to see what impact it has on the final executables. &lt;/P&gt;
&lt;P&gt;As time goes by, I'm sure there will be&amp;nbsp;more tweaking to be done but, in all likelihood, any significant performance gains are going to be the result some modification of the PHP codebase itself.&lt;/P&gt;&lt;img src="http://port25.technet.com/aggbug.aspx?PostID=26365" width="1" height="1"&gt;</description><category domain="http://port25.technet.com/archive/tags/Interop/default.aspx">Interop</category><category domain="http://port25.technet.com/archive/tags/Dynamic+Languages/default.aspx">Dynamic Languages</category><category domain="http://port25.technet.com/archive/tags/Community/default.aspx">Community</category><category domain="http://port25.technet.com/archive/tags/PHP/default.aspx">PHP</category><category domain="http://port25.technet.com/archive/tags/Open+Source/default.aspx">Open Source</category><category domain="http://port25.technet.com/archive/tags/_7E00_FeaturedPost/default.aspx">~FeaturedPost</category><category domain="http://port25.technet.com/archive/tags/Garrett+Serack/default.aspx">Garrett Serack</category></item><item><title>Crafting a Better PHP Build Process on Windows – Part II</title><link>http://port25.technet.com/archive/2009/06/11/crafting-a-better-php-build-process-on-windows-part-ii.aspx</link><pubDate>Thu, 11 Jun 2009 20:10:00 GMT</pubDate><guid isPermaLink="false">af7480c4-26b7-468d-87b0-2acebabb473d:26189</guid><dc:creator>Garrett Serack</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://port25.technet.com/rsscomments.aspx?PostID=26189</wfw:commentRss><comments>http://port25.technet.com/archive/2009/06/11/crafting-a-better-php-build-process-on-windows-part-ii.aspx#comments</comments><description>&lt;P&gt;&lt;EM&gt;I talked about getting started in building the PHP stack in my &lt;A class="" href="http://port25.technet.com/archive/2009/06/09/optimizing-php-part-1.aspx" target=_blank mce_href="http://port25.technet.com/archive/2009/06/09/optimizing-php-part-1.aspx"&gt;last post&lt;/A&gt;, now I'm taking it...&lt;/EM&gt;&lt;/P&gt;
&lt;H5&gt;&lt;U&gt;One step further&lt;/U&gt;&lt;/H5&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;EM&gt;"We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil." - Donald Knuth &lt;/EM&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;A chance conversation I had last summer at OSCON with &lt;A class="" href="http://port25.technet.com/archive/2009/02/10/welcome-snakebite-the-newest-open-network-in-town.aspx" target=_blank mce_href="http://port25.technet.com/archive/2009/02/10/welcome-snakebite-the-newest-open-network-in-town.aspx"&gt;Trent Nelson&lt;/A&gt;&amp;nbsp;- who was building Python on Windows -&amp;nbsp;planted the seeds of how to get PHP on Windows optimized further.&amp;nbsp; Trent was using the PGO features of Visual Studio to generate Python binaries that run faster.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;Rather than spend a lot of time optimizing all the little bits of PHP itself, I thought that this would be an ideal way to improve the overall speed of PHP, provided I could find the right scenarios to train &lt;A class="" href="http://port25.technet.com/archive/2009/05/29/migrating-php-apps-to-windows.aspx" target=_blank mce_href="http://port25.technet.com/archive/2009/05/29/migrating-php-apps-to-windows.aspx"&gt;PHP&lt;/A&gt; with.&amp;nbsp; Little did I know that finding the right scenarios wasn't the hardest part. &lt;/P&gt;
&lt;P mce_keep="true"&gt;
&lt;TABLE class="" cellSpacing=0 cellPadding=2 width="100%" border=0&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="" vAlign=top width=50&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD class="" vAlign=top bgColor=#c0c0c0&gt;&lt;A href="http://en.wikipedia.org/wiki/Profile-guided_optimization"&gt;&lt;STRONG&gt;What is PGO?&lt;/STRONG&gt;&lt;/A&gt;&lt;STRONG&gt; &lt;/STRONG&gt;&lt;EM&gt;(from Wikipedia) &lt;BR&gt;&lt;STRONG&gt;Profile-guided optimization&lt;/STRONG&gt; (&lt;B&gt;PGO&lt;/B&gt;) is a &lt;/EM&gt;&lt;A class="" href="http://en.wikipedia.org/wiki/Compiler" target=_blank mce_href="http://en.wikipedia.org/wiki/Compiler"&gt;&lt;EM&gt;compiler&lt;/EM&gt;&lt;/A&gt;&lt;EM&gt; optimization technique in &lt;/EM&gt;&lt;A class="" href="http://en.wikipedia.org/wiki/Computer_programming" target=_blank mce_href="http://en.wikipedia.org/wiki/Computer_programming"&gt;&lt;EM&gt;computer programming&lt;/EM&gt;&lt;/A&gt;&lt;EM&gt; to improve program runtime performance. In contrast to traditional optimization techniques that solely use the &lt;/EM&gt;&lt;A href="http://en.wikipedia.org/wiki/Source_code"&gt;&lt;EM&gt;source code&lt;/EM&gt;&lt;/A&gt;&lt;EM&gt;, PGO uses the results of test runs of the instrumented program to optimize the final generated code. The compiler is used to access data from a sample run of the program across a representative input set. The data indicates which areas of the program are executed more frequently, and which areas are executed less frequently. All optimizations benefit from profile-guided feedback because they are less reliant on &lt;/EM&gt;&lt;A class="" href="http://en.wikipedia.org/wiki/Heuristic" target=_blank mce_href="http://en.wikipedia.org/wiki/Heuristic"&gt;&lt;EM&gt;heuristics&lt;/EM&gt;&lt;/A&gt;&lt;EM&gt; when making compilation decisions.&lt;/EM&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/P&gt;
&lt;H5&gt;&lt;U&gt;Adding PGO to the existing build process &lt;/U&gt;&lt;/H5&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;EM&gt;"I have not failed, I've just found 10,000 ways that won't work." - Thomas Edison&lt;/EM&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I had downloaded the source to the dependent libraries off the PHP wiki, checked out the &lt;A class="" href="http://port25.technet.com/archive/2009/05/12/announcing-the-php-sdk-for-windows-azure.aspx" target=_blank mce_href="http://port25.technet.com/archive/2009/05/12/announcing-the-php-sdk-for-windows-azure.aspx"&gt;PHP source code&lt;/A&gt;, and begun the process of adding in PGO support to the existing build process. This proved to be extremely difficult.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;Even limiting the scope to just the core of PHP itself - without the dependent libraries - I ran into trouble trying to compile using PGO instrumentation and then re-linking after running some tests.&amp;nbsp; The make file that gets generated by the configure.js script (a JScript version of the automake configure script for the Windows platform) was just not built with what I had in mind. &lt;/P&gt;
&lt;P&gt;I spent the better part of two weeks trying different approaches to tweaking the makefile so that I could use PGO to improve the &lt;A class="" href="http://port25.technet.com/archive/2009/05/11/php-5-3-rc2-highly-optimized-for-windows.aspx" target=_blank mce_href="http://port25.technet.com/archive/2009/05/11/php-5-3-rc2-highly-optimized-for-windows.aspx"&gt;PHP executable&lt;/A&gt;, but I kept running into roadblocks.&amp;nbsp; Worse, the closer I got to a makefile that did what I wanted, the farther away from the current build process I was getting, and I wasn't sure that what I would end up with would even be close to what was being built today. &lt;/P&gt;
&lt;H5&gt;&lt;U&gt;The long dark winter road &lt;/U&gt;&lt;/H5&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;EM&gt;"Only the meek get pinched. The bold survive." - Ferris Bueller&lt;/EM&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I came to the conclusion that I'd have to build new Visual Studio project files from scratch.&amp;nbsp; What worried me was that this would end up to be a completely different build process, and I'd never get the community to abandon what was already working, so I'd better be able to rebuild these new project files easily.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I started looking (inside Microsoft and out) for any tools which generated Visual C++ project files.&amp;nbsp; I found someone internally who had used some JScript to create project files from text files, but after some experimentation, I found this was nowhere near what I needed.&amp;nbsp; What I really needed was a way to convert the generated Makefile into a .vcproj file-and not just 'wrap' it. &lt;/P&gt;
&lt;P&gt;Once I found there was no such tool* , I began trying to figure out how to create one. I had this idea a few times in the last decade or so: watch how a program is compiled, and create a project file that does the same thing. Having tossed around the idea in my head before, I knew it wasn't going to be trivial but, without it, I couldn't do what needed to be done. &lt;/P&gt;
&lt;P mce_keep="true"&gt;
&lt;TABLE class="" cellSpacing=0 cellPadding=2 width="100%" border=0&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="" vAlign=top width=50&gt;&lt;EM&gt;&lt;/EM&gt;&lt;/TD&gt;
&lt;TD class="" vAlign=top&gt;&lt;EM&gt;* Let me tell you: you &lt;STRONG&gt;never&lt;/STRONG&gt; want to think about writing a tool to parse out what a makefile does.&amp;nbsp; It's rather like making a tool that tells you how sausage is made, in excruciating detail. Ugh.&lt;/EM&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;In Part III, I'll talk about the trouble with observing the build process.&lt;/EM&gt;&lt;/P&gt;&lt;img src="http://port25.technet.com/aggbug.aspx?PostID=26189" width="1" height="1"&gt;</description><category domain="http://port25.technet.com/archive/tags/Interop/default.aspx">Interop</category><category domain="http://port25.technet.com/archive/tags/Dynamic+Languages/default.aspx">Dynamic Languages</category><category domain="http://port25.technet.com/archive/tags/Community/default.aspx">Community</category><category domain="http://port25.technet.com/archive/tags/Open+Source/default.aspx">Open Source</category><category domain="http://port25.technet.com/archive/tags/_7E00_FeaturedPost/default.aspx">~FeaturedPost</category><category domain="http://port25.technet.com/archive/tags/Garrett+Serack/default.aspx">Garrett Serack</category></item></channel></rss>