<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Jacob Santos &#187; opcode</title>
	<atom:link href="http://jacobsantos.com/tags/opcode/feed/" rel="self" type="application/rss+xml" />
	<link>http://jacobsantos.com</link>
	<description>Rumblings, rants, essays, stories by Jacob Santos about Web Site Development, Persistent Browser-Based Games, personal journal, and Programming.</description>
	<lastBuildDate>Thu, 28 Jan 2010 13:33:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=3.0-alpha</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>In Response to JIT Compilation</title>
		<link>http://jacobsantos.com/2007/writing-projects/in-response-to-jit-compilation/</link>
		<comments>http://jacobsantos.com/2007/writing-projects/in-response-to-jit-compilation/#comments</comments>
		<pubDate>Fri, 27 Apr 2007 04:41:56 +0000</pubDate>
		<dc:creator>santosj</dc:creator>
				<category><![CDATA[Writing Projects]]></category>
		<category><![CDATA[just-in-time]]></category>
		<category><![CDATA[opcode]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.santosj.name/programming/php-related/php-opcode/jit/in-response-to-jit-compilation/</guid>
		<description><![CDATA[I understand now or at least a little bit more why JIT compilation wouldn&#8217;t be useful.
Most pages will take less than a second to execute. Caching, where possible, will also be used to further decrease the time. Opcode Caches can also be used to keep PHP from compiling the page with each request further decreasing [...]]]></description>
			<content:encoded><![CDATA[<p>I understand now or at least a little bit more why JIT compilation wouldn&#8217;t be useful.</p>
<p>Most pages will take less than a second to execute. Caching, where possible, will also be used to further decrease the time. Opcode Caches can also be used to keep PHP from compiling the page with each request further decreasing the time it takes. Taken all together most professional web sites wouldn&#8217;t benefit from JIT compilation. Given the delay from converting to machine code, it might actually take longer on the first run.</p>
<p>Would it be quicker to write a C extension for PHP than building a JIT compiler for the Zend Engine? Yes. In the discussion with Frameworks, the solution is to write the slow PHP code in C and write a function to be called in PHP, if available. My argument has always been that I shouldn&#8217;t have to. If it is just as fast using JIT compilation than I shouldn&#8217;t have to touch C code unless I&#8217;m binding some library in C or C++ to be used in PHP. </p>
<p>Yeah, 2x time decrease (<a href="http://www.roadsend.com/home/index.php">Roadsend</a> compiler statistics) doesn&#8217;t sound like much, but I would like to run algorithms that normally take 15 to 30 seconds in half the time. That to me is a huge deal. Now, these algorithms won&#8217;t run in front end pages, of course, but I would like to maintain the code in PHP. The possibility of the algorithm being poor is there, and so is that it would be better writing the code in C/C++.</p>
<p>Well, what I&#8217;m trying to get at, is that with edge cases JIT compilation would make a lot of sense. For those with normal pages, then I concede that you are correct.</p>

<p><strong>Possibly Related Posts:</strong></p>
<ul>
<li><a href="http://jacobsantos.com/2007/writing-projects/english-iv-untitled-satire/">English IV: Untitled Satire</a></li>
<li><a href="http://jacobsantos.com/2007/writing-projects/opcode-theory-userland-multitasking-introduction/">Userland Multitasking: Introduction</a></li>
<li><a href="http://jacobsantos.com/2007/writing-projects/php-opcode-series/">PHP Opcode Series</a></li>
<li><a href="http://jacobsantos.com/2006/writing-projects/quest-for-magic-vincent-draft-1/">Quest For Magic: Vincent Draft 1</a></li>
<li><a href="http://jacobsantos.com/2006/writing-projects/how-to-start-spirit-keeper/">How to Start Spirit Keeper</a></li>
</ul><br />
]]></content:encoded>
			<wfw:commentRss>http://jacobsantos.com/2007/writing-projects/in-response-to-jit-compilation/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>You&#8217;ll Rue The Day</title>
		<link>http://jacobsantos.com/2007/programming/youll-rue-the-day/</link>
		<comments>http://jacobsantos.com/2007/programming/youll-rue-the-day/#comments</comments>
		<pubDate>Mon, 23 Apr 2007 13:10:56 +0000</pubDate>
		<dc:creator>santosj</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[humor]]></category>
		<category><![CDATA[just-in-time]]></category>
		<category><![CDATA[opcode]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.santosj.name/programming/php-related/php-opcode/jit/youll-rue-the-day/</guid>
		<description><![CDATA[You know, whenever someone tells me I can&#8217;t do something or that something I think is possible is impossible, it makes me try even harder to prove them wrong or in most cases, prove them right. Either way, both sides comes out great. I say that because it proves nothing to the other side if [...]]]></description>
			<content:encoded><![CDATA[<p>You know, whenever someone tells me I can&#8217;t do something or that something I think is possible is impossible, it makes me try even harder to prove them wrong or in most cases, prove them right. Either way, both sides comes out great. I say that because it proves nothing to the other side if I prove them wrong, because we both benefited from the experience. I&#8217;m not out to make fun or embarrass anyone. If I turn out to be wrong, then I learn a valuable lesson of one that will be hard to forget and they get further evidence to use for the next guy that challenges them.</p>
<p>Win/Win.</p>
<p>I&#8217;m going to try even harder now that enough people are saying that I&#8217;m not right (which is nicer than saying I&#8217;m wrong) on Just-in-Time compilation benefits for PHP. I really do think the extra seconds saved will great impact what PHP can be used for in the future. Judging from a working PHP 4 compiler, it cuts the time in half. Let us say for a moment that you have to process 100 datasets that takes .15 seconds each iteration. That is <strong>15 seconds</strong>. If you compile it and it only takes .075 seconds, then well, it would only take 7.5 seconds. It is a poor example, but the point I&#8217;m trying to make is if you cut the time, even by a fraction, it can save a lot within a loop.</p>
<p>Yeah, sure it isn&#8217;t going to be a huge deal for front end sites because they won&#8217;t have anything that within a loop that takes that long. Even if they had a loop, they would use caching so that users wouldn&#8217;t notice the speed decrease. If you are doing gaming, math intensive, or heavy processing, it can get ugly very fast and limit you quickly on what you can afford to do time and processing on shared hosts.</p>
<p>The only way to know for sure whether or not JIT will benefit users, is to have a working and optimized solution for which testing can occur. My ultimate goal and I hope by next year I&#8217;ll have a working version that can be tested. Along the way, I have other side quests I need to complete before I can get from point &#8216;A&#8217;, which is not having JIT implementation, to point &#8216;B&#8217;, where I have a working implementation.</p>
<p>Not that I care whether or not it speeds PHP up, it would be nice. By this time next year I would know a lot more about Python than I do now and PHP JIT would be less important. My motivation is more compiler theory and always wanting to do something like this. The wealth of knowledge within the Zend and PHP engines is massive and anyone would learn a great deal tweaking and lurking around within them.</p>
<p>So, something next year, I want to either prove I&#8217;m right (hopefully that will be the case) or I&#8217;ll just prove what everyone else is saying and slowly bow my head momentarily in shame.</p>

<p><strong>Possibly Related Posts:</strong></p>
<ul>
<li><a href="http://jacobsantos.com/2010/programming/easier-apis-for-wordpress/">Easier APIs for WordPress</a></li>
<li><a href="http://jacobsantos.com/2010/programming/libraries-should-use-liberal-licenses/">Libraries Should Use Liberal Licenses</a></li>
<li><a href="http://jacobsantos.com/2009/programming/why-writing-documentation-wasnt-a-waste-of-time/">Why Writing Documentation Wasn&#8217;t a Waste of Time</a></li>
<li><a href="http://jacobsantos.com/2009/programming/contradiction-of-good-object-oriented-design/">Contradiction of Good Object-Oriented Design</a></li>
<li><a href="http://jacobsantos.com/2009/programming/wtf-are-people-still-writing-php-template-engines/">WTF Are People Still Writing PHP Template Engines</a></li>
</ul><br />
]]></content:encoded>
			<wfw:commentRss>http://jacobsantos.com/2007/programming/youll-rue-the-day/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Userland Multitasking: Introduction</title>
		<link>http://jacobsantos.com/2007/writing-projects/opcode-theory-userland-multitasking-introduction/</link>
		<comments>http://jacobsantos.com/2007/writing-projects/opcode-theory-userland-multitasking-introduction/#comments</comments>
		<pubDate>Fri, 16 Mar 2007 21:33:31 +0000</pubDate>
		<dc:creator>santosj</dc:creator>
				<category><![CDATA[Writing Projects]]></category>
		<category><![CDATA[opcode]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Theory]]></category>

		<guid isPermaLink="false">http://www.santosj.name/programming/php-related/php-opcode/opcode-theory-userland-multitasking-introduction/</guid>
		<description><![CDATA[Difficulty
At my current level of skill and understanding, this feature would be impossible for me to implement on my own. It is just an introductory  look at what the other sections will visually look like when they are also finished. I will not be implementing this feature.
Introduction
Multi-threading should not be allowed at the user [...]]]></description>
			<content:encoded><![CDATA[<h3>Difficulty</h3>
<p>At my current level of skill and understanding, this feature would be <strong>impossible</strong> for me to implement on my own. It is just an introductory  look at what the other sections will visually look like when they are also finished. I will not be implementing this feature.</p>
<h3>Introduction</h3>
<p>Multi-threading should not be allowed at the user level, but allow for sandbox threading. The PHP Engine should keep track of the creation of threads, protect against deadlocking, and control synchronization. This will abstract away the complexity and have PHP do all of the heavy lifting as well as protect the developers from themselves and harming the process the thread is in.</p>
<p>There are some architectures, both CPU and OS, that do not allow threading. There should be a fall back implemented in the virtual machine that still enables an environment functionally similar to threading. The fall back can be implemented like the ticks in the current PHP Engine or it could use a stack approach similar to operating systems.</p>
<p>The Engine could also track how efficient the system is and how well it would perform if it was single threaded. There should be a mix of allowing the developers to test and optimize on their own and tracking internally to help protect against slow scripts caused by wrong usage of this feature. </p>
<p>There should be internal reflection for threading to allow for tracking, overriding, and debugging. The reflection will track the time a thread takes, which threads and variables it is synchronized with, and how many times faults occurred. There should be functions for overriding whether or not the thread is still multi-threaded or if it creates an interprocess, or if it is instead acts like a single thread, when processed.</p>
<p>The multi-threading feature wouldn&#8217;t be useful, if the process shutdown and destroyed everything at execution. The feature would only be enabled for PHP environments that are already multi-tasked to keep the script from taking longer than it should.</p>
<h3>Virtual Machine: Timing the Best Method</h3>
<p>During runtime, the virtual machine can keep track of the time the script takes and switch between single threaded and multiple threads to get statistics on which would be the best method overall. After it figures which is the best method for the user, it can either log what it finds, allow for reflection to get the number, and then decide which is the best method to take. It would still work like the user expects, but allow for the virtual machine to decide which is the best method for the user.</p>
<p>This would add additional memory and processing overhead, so it could be disabled by those who already think that their script is optimized enough already. This adds another level of complexity to the feature and could introduce difficult to find and fix bugs. It should also be allowed to be overwritten by the user for those who know for a fact that the system doesn&#8217;t work that well for their script. The system won&#8217;t be able to work perfectly 100% of the time for every script.</p>
<p>This additional feature would be extremely useful for JIT or opcode cached environments where the script is stored in memory for extended periods of time. Keeping track of timing of various environments would allow for the system to rewrite itself to optimize the speed for the user. The abstraction would be such that the user wouldn&#8217;t be able to tell, except when the system fully realizes and optimizes itself and the script.</p>
<h3>Keywords</h3>
<p>The following sections will introduce additional keywords and syntax that will require that the flex and bison skeletons be updated to allow for this feature. This section will not be updated and will not be found here.</p>
<h3>Different Methods for Creating Threads</h3>
<p>The following parts will detail the various parts of this feature and will be split up to allow for better understanding on what the feature will involve.</p>
<ol>
<li>
Anonymous</p>
<ul>
<li>Does not allow for returning to main thread or calling from the main thread.</li>
<li>Runs along side the main thread.</li>
</ul>
</li>
<li>
Named</p>
<ul>
<li>Does not run unless called from the main process.</li>
<li>Can return data to the calling thread.</li>
</ul>
</li>
<li>
Shell</p>
<ul>
<li>Allows for shell commands to be processed in another thread or process.</li>
<li>Allows for returning to the calling thread.</li>
<li>Allows for both anonymous and named shells.</li>
<li>It would replace functionality, most of the shell extensions, when implemented.</li>
</ul>
</li>
<li>
Interprocess</p>
<ul>
<li>Replaces the current method of the Process Control extension with an easier to setup and create method.</li>
<li>Also will allow for connecting to other processes for passing data.</li>
</ul>
</li>
</ol>

<p><strong>Possibly Related Posts:</strong></p>
<ul>
<li><a href="http://jacobsantos.com/2007/writing-projects/english-iv-untitled-satire/">English IV: Untitled Satire</a></li>
<li><a href="http://jacobsantos.com/2007/writing-projects/in-response-to-jit-compilation/">In Response to JIT Compilation</a></li>
<li><a href="http://jacobsantos.com/2007/writing-projects/php-opcode-series/">PHP Opcode Series</a></li>
<li><a href="http://jacobsantos.com/2006/writing-projects/quest-for-magic-vincent-draft-1/">Quest For Magic: Vincent Draft 1</a></li>
<li><a href="http://jacobsantos.com/2006/writing-projects/how-to-start-spirit-keeper/">How to Start Spirit Keeper</a></li>
</ul><br />
]]></content:encoded>
			<wfw:commentRss>http://jacobsantos.com/2007/writing-projects/opcode-theory-userland-multitasking-introduction/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PHP Opcode Series</title>
		<link>http://jacobsantos.com/2007/writing-projects/php-opcode-series/</link>
		<comments>http://jacobsantos.com/2007/writing-projects/php-opcode-series/#comments</comments>
		<pubDate>Wed, 14 Mar 2007 02:43:42 +0000</pubDate>
		<dc:creator>santosj</dc:creator>
				<category><![CDATA[Writing Projects]]></category>
		<category><![CDATA[opcode]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Theory]]></category>

		<guid isPermaLink="false">http://www.santosj.name/php/php-opcode/php-opcode-series/</guid>
		<description><![CDATA[Introduction
The PHP Opcode series will take a look at the theory and implementation of working with the Zend Engine in the specific areas of adding opcodes and enabling language features. The specific areas will be how it would look in the PHP language, how it would look as PHP opcodes, and how it would look [...]]]></description>
			<content:encoded><![CDATA[<h3>Introduction</h3>
<p>The PHP Opcode series will take a look at the theory and implementation of working with the Zend Engine in the specific areas of adding opcodes and enabling language features. The specific areas will be how it would look in the PHP language, how it would look as PHP opcodes, and how it would look as Assembler for looking at enabling JIT compiling later.</p>
<p>The posts will be researched and go through multiple drafts for professionalism before posting. In this hope, it will strive to enable discussion that isn&#8217;t flaming and collective of the topic at hand. For as much as I can achieve at my level of writing skill and researching the topic at hand.</p>
<p>(<strong>Honestly, I&#8217;m spending more time on these posts than I do on my school research papers&#8230; which is to still say that I am doing more than previous posts.</strong>)</p>
<h3>Purpose</h3>
<p>I want to add JIT compiling to the current Zend Engine and before I can do that I will have to learn how the Zend Engine works. The best way would be to read a book or learn from the minds that created it. There is a current lack of printed material on extending the Zend Engine and I&#8217;ll rather not bother the Zend Engine masters with my countless n00bish questions. I&#8217;ll wait to ask those questions for whenever I hit a road block or can&#8217;t find the answer myself.</p>
<p>I&#8217;m going to try to implement some of the easier features of the &#8220;Opcode Theory&#8221; part to learn how different areas of the Zend Engine work. I&#8217;ll also intentionally break the Engine and learn from there. Such questions as, &#8220;I wonder what would happen if I add this?&#8221; or &#8220;What if I change this to my own code.&#8221;</p>
<p>I&#8217;m tempted to rewrite the entire thing to my achieve my own goals, but that would negate the point of these exercises. </p>
<p>Not that I will implement all of the theory, but to think about how it would be possible. To learn how PHP uses Opcodes and how it can be improved and optimized by using more. By writing theory and how the current Zend Engine works, I can remember better and try to implement my ideas to see if they are possible.</p>
<h3>Areas of Focus</h3>
<p>There will be areas of focus with titles for keeping order of which post is for what.</p>
<ul>
<li>Opcode Theory</li>
<li>Opcode Implementation</li>
<li>Opcode Documentation</li>
</ul>
<h3>Opcode Theory</h3>
<p>These posts will abstract out the problem and how it <strong>could</strong> look once implemented. From above, the sections will be PHP userland code, PHP Opcode, and finally how it would look as Assembler for JIT. The Assembler isn&#8217;t much use for the JIT, but it will help to think about solutions once JIT is finally implemented. The JIT and Assembler will achieve the same functionality of converting opcodes to machine code. </p>
<p>It would be nice to see it in action outside of PHP, using Assembler, before implementing the feature using the JIT library. Getting Assembler code to work against the Zend Engine and PHP will also be part of the Implementation, which is outside the scope of the Theory. It is just to say that the Theory part will have puesdo-Assembler code for how it might look.</p>
<p>I will not be implementing all of these theory posts and I will be lucky if I even implement one. My main purpose is learning enough of the Opcode parts of the Zend Engine to hook into and write a Zend Engine extension that enables JIT compilation. These side projects should help to learn enough to accomplish that much.</p>
<h3>Opcode Implementation</h3>
<p>Will document how well I&#8217;m doing implementing some of the theory and eventually the JIT feature for the Zend Engine. In the event that I do implement one of the features in the theory part, I will post what it finally looks like and how it works. These posts will also include the road and difficulties in implementing the features in the theory posts and eventually how it was done.</p>
<h3>Opcode Documentation</h3>
<p>I expect that I&#8217;ll learn a lot by the above mangling of the Zend Engine and picking at the minds and team behind the Zend Engine. Some things I will have to learn myself and I&#8217;ll post them in this heading to make sure that I&#8217;ll remember them when I come back after an extended break or two to work on other projects.</p>
<p>&#8220;Hmm, how did I do that one thing again? Oh yeah, I wrote about that!&#8221; and also to store help I will eventually (hopefully) receive from the PHP lists.</p>

<p><strong>Possibly Related Posts:</strong></p>
<ul>
<li><a href="http://jacobsantos.com/2007/writing-projects/english-iv-untitled-satire/">English IV: Untitled Satire</a></li>
<li><a href="http://jacobsantos.com/2007/writing-projects/in-response-to-jit-compilation/">In Response to JIT Compilation</a></li>
<li><a href="http://jacobsantos.com/2007/writing-projects/opcode-theory-userland-multitasking-introduction/">Userland Multitasking: Introduction</a></li>
<li><a href="http://jacobsantos.com/2006/writing-projects/quest-for-magic-vincent-draft-1/">Quest For Magic: Vincent Draft 1</a></li>
<li><a href="http://jacobsantos.com/2006/writing-projects/how-to-start-spirit-keeper/">How to Start Spirit Keeper</a></li>
</ul><br />
]]></content:encoded>
			<wfw:commentRss>http://jacobsantos.com/2007/writing-projects/php-opcode-series/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>
