3 ms·
In the context there was no compiler, there was an interpreter. PHP compilers (which do exist) might remove this type of redundancy, the PHP interpreter likely
by Someone1234 12y ago
In the context there was no compiler, there was an interpreter. PHP compilers (which do exist) might remove this type of redundancy, the PHP interpreter likely won't for reasons stated elsewhere in the comments.
- kyberias 12y agoBut doesn't PHP compile the source code into byte code and then interpret that? The problem described here was in the _compiler_ part of PHP, not in the byte code interpreter.
- jiggy2011 12y agoWhy is this downvoted? it is a reasonable question.
- mackal 12y agoBecause its more aruging about semantics than anything else. At the end of the day, it needs to do this in real time and optimizing would cause a loss of speed for sometimes faster executed code, but since it all counts every time, it would be a waste.
- jiggy2011 12y agoOpcodes can be cached until the source file changes. There may be specific instances when caching cannot happen, but the poster seems to not be clear as to why that would apply in this case, hence the question.
- Someone1234 12y agoAll of which needs to occur after the user makes a request but before the request is returned. Regardless of which word you wish to use (compiler, interpreter, lexer, etc) or which part of the process you wish to shift the workload into, that work (finding redundancies and removing them) is still being performed in real time after a request arrives (i.e. a user has to wait while we do this). If the redundancy check costs more than the redundancy itself then removing them is utterly fruitless. The only way to avoid that is to take it out of that pipeline (i.e. pre-optimise the PHP OPCodes before a request arrives). PHP pre-compilers and other optimisers absolutely exist and are readily used (e.g. HipHop). Within which case it might not matter if you used GOTO or While(true) as they'd both likely get optimised down to the GOTO OPCodes. However if you're using the original PHP interpreter then leaving them in might be the most optimal/cheap path to follow.
- masklinn 12y ago> The only way to avoid that is to take it out of that pipeline (i.e. pre-optimise the PHP OPCodes before a request arrives). Most production installations of PHP pretty much mandate a bytecode cache and the official distribution bundles one since 5.5[0], so the redundancy check is done once but the optimisation works for any request thereafter. > PHP pre-compilers and other optimisers absolutely exist and are readily used (e.g. HipHop). HHVM is a completely separate VM which does not use (or consume, or care for in any way) the Zend bytecode produced by the Zend VM. HHVM has its own separate and incompatible bytecode format called HHBC[1]. It's neither a "pre-compiler" nor an "optimiser" for the Zend VM. [0] http://php.net/manual/en/opcache.installation.php http://php.net/manual/en/opcache.installation.php [1] https://github.com/facebook/hhvm/blob/master/hphp/doc/bytecode.specification https://github.com/facebook/hhvm/blob/master/hphp/doc/byteco...
- Someone1234 12y ago> It's neither a "pre-compiler" nor an "optimiser" for the Zend VM. Nobody claimed otherwise.
- masklinn 12y ago> Nobody claimed otherwise. You provided HHVM as an example[0] of "PHP pre-compilers and other optimisers". [0] that's literally what 'e.g.' means, it's an abbreviation for "exempli gratia", latin for "for example"
- Someone1234 12y agoIndeed I did, and indeed it is. You tacked on "for the Zend VM." Which was not something I said. I said: > PHP pre-compilers and other optimisers absolutely exist and are readily used (e.g. HipHop). You then said: > HHVM is a completely separate VM which does not use (or consume, or care for in any way) the Zend bytecode produced by the Zend VM. HHVM has its own separate and incompatible bytecode format called HHBC[1]. It's neither a "pre-compiler" nor an "optimiser" for the Zend VM. Which is really answering a point nobody made. It is just completely out of the blue. My post literally does not contain the term "Zend." Nor does it make any claim to what OPCode formats different things use (and really the only reason you could even talk about HipHop was that it was given as a unqualified example). So to this: > It's neither a "pre-compiler" nor an "optimiser" for the Zend VM. Is answering a point nobody made. It is like me saying, "You're wrong, the White House isn't blue, it is white!" When no claims to the blueness of the White House were made by yourself.
- alayne 12y agoIgorw's post uses the word compiler four times.
- Someone1234 12y agoPHP compiles but acts as an interpreter. The Wikipedia article covers this[0]: > The Zend Engine compiles PHP source code on-the-fly into an internal format that it can execute, thus it works as an interpreter. I won't get drawn into a highly dull debate on the definition of what an interpreter is or isn't. Instead let's just agree that PHP by default generates the OPCodes every single time a request comes in. That's all we need to understand for this context (that OPCode generation is in-line with requests, not pre-compiled or otherwise cached). Also, yes, there are tons and tons of implementations of PHP caching/precompilation/JIT/etc. [0] https://en.wikipedia.org/wiki/PHP#Implementations https://en.wikipedia.org/wiki/PHP#Implementations
- deleted 12y ago[deleted]
- kyberias 12y agoThe original author wanted to generate byte code that executes as efficiently as possible. Clearly scoped goal. :) Because PHP's compiler component, which he refers to as "compiler", did not generate efficient byte code for the interpreter, he had to use GOTO to force the compiler to generate it. Whether the byte codes get cached or not might be irrelevant to his goals. We cannot be certain what proportion of time is wasted in network, compilation or serving the request. It could be one way or another. USUALLY this is a waste of time. The developer's time that is.
- DonHopkins 12y agoPHP compilers are useful for optimizing SQL injection attacks.
- collyw 12y agoAnywhere I can find out more about this?