3 ms·
The key word there is interpreter. When you compile you have near infinite time to try and optimise and remove redundancy. When you interpret (i.e. real-time co
by Someone1234 12y ago
The key word there is interpreter. When you compile you have near infinite time to try and optimise and remove redundancy. When you interpret (i.e. real-time compilation) you have to decide if the redundancy check is more expensive than removing the redundancy.
Take this example, it is one extra OP Code instruction, which might generate a handful of ASM that actually gets run. How many ASM instructions would it take to detect this (and make sure there are no externalities) and remove it? I'd imagine considerably more.
And worse still you're also performing all of these redundancy checks even when there is nothing to remove. So now you've increased the cost to ALL loops, not just static ones with no purpose.
TL;DR: It is more expensive to detect and remove than to ignore.
- masklinn 12y ago> Take this example, it is one extra OP Code instruction, which might generate a handful of ASM that actually gets run. How many ASM instructions would it take to detect this (and make sure there are no externalities) and remove it? I'd imagine considerably more. The detection is only done one while generating the bytecode, but the extraneous bytecode instructions have to be executed every time the loop… loops. Not only that but it's a very simple optimisation to apply (even CPython is able to discover it).
- Someone1234 12y ago> The detection is only done one while generating the bytecode That isn't how PHP natively works. It is an interpreted language with compiler addons. It has to be done per every single request (as the CGI process may collapses after each one). If you use something like HipHop or PHP accelerator then you can get cached OPCodes, and can also perform optimisation at that stage. But you cannot assume PHP will be executed in those environments. PHP is not Java.
- masklinn 12y ago> That isn't how PHP natively works. Yes it is. > It has to be done per every single request Yes? And the loop will most likely loop multiple times per request, which is my point. > If you use something like HipHop or PHP accelerator then you can get cached OPCodes HHVM is a completely separate and unrelated product. And you don't need "PHP accelerator" because the Zend VM bundles a bytecode cache since 5.5[0], not that it has any relevance to my point. > But you cannot assume PHP will be executed in those environments. Good thing I wasn't assuming anything then. [0] http://php.net/manual/en/book.opcache.php http://php.net/manual/en/book.opcache.php
- Someone1234 12y agoWait, let's backtrack here. I said that natively PHP doesn't cache and the OPCodes are generated every request. You said "Yes it is." meaning presumably you don't feel like that is the case. You then go on to link to Zend Opcache which is, by all accounts, an extension which provides caching and which wasn't even bundled with PHP until 5.5 (according to yourself). So from 0.1 through 5.4 PHP shipped with zero caching and thus a core part of the language at that time was that it was generated every request. Now, 5.5 was released in June 2013. So for a lot of users PHP remains a language which is interpreted when a user makes a request. And even users on 5.5+, the first request per page is effectively interpreted as the cache isn't pre-populated. So really what is it that we are even discussing? Seems like a debate about semantics at this stage.
- ajanuary 12y agoBear in mind any new optimizations would be added to 5.5+, which would presumably have opcode caching by default? [Edit] Maybe a whole new world of possible optimizations has just opened up.
- masklinn 12y ago5.5 bundles an opcode cache in the default distribution, but the cache isn't enabled by default AFAIK.
- masklinn 12y ago> I said that natively PHP doesn't cache and the OPCodes are generated every request. You said "Yes it is." meaning presumably you don't feel like that is the case. Since when do you backtrack to a completely different subtread (or to a subthread which does not exist)? * I said that the detection (optimisation) would be performed while generating the bytecode * You asserted that it's not how PHP works by default * I replied that it is You've asserted that Zend PHP does not use an intermediate bytecode during normal operation, do you stand by it? Because that's where we end up if we backtrack, not about the fact that it doesn't cache bytecode by default which is not actually relevant to my point (the existence and widespread use of bytecode cache merely supports said point by further improving the ROI).