Hey:

On Sat, Jan 17, 2015 at 12:12 AM, Dmitry Stogov <dmi...@zend.com> wrote:
> Hi Benjamin,
>
> Thanks for idea.
> With PHP7 AST compiler, it's quite easy to implement this (it took us 15
> minutes to try :)
yeah... by handy :)

> However, it doesn't make big improvement on our benchmarks.
in reallife app, IR has no significant difference while running
wordpress homepage

thanks
> We will take a look into possibilities to apply your idea to other patterns
> (e.g. for and foreach loops).
>
> Anyway, it makes full sense to include this optimization into PHP7.
> I just like to try other opportunities first.
>
> Thanks. Dmitry.
>
> On Fri, Jan 16, 2015 at 10:56 AM, Benjamin Coutu <ben.co...@zeyos.com>
> wrote:
>>
>> Hello,
>>
>> Please consider the following PHP code:
>>
>> while ( <CONDITION> ) {
>>   <STATEMENT>
>> }
>>
>> It currently compiles to something like this for the Zend Engine:
>>
>> 0: <CONDITION>
>> 1: JMPZ -> 4
>> 2: <STATEMENT>
>> 3: JMP -> 0
>> 4: ...
>>
>> This can easily be rewritten in an equivalent but much more efficient
>> form:
>>
>> 0: JMP -> 2
>> 1: <STATEMENT>
>> 2: <CONDITION>
>> 3: JMPNZ -> 1
>>
>> The trick is to jump to the conditional expression before the first
>> iteration and then only having to continue with just on conditional jump on
>> every subsequent cycle.
>>
>> This would result in only 1 jump per loop iteration compared to
>> effectively 2 jumps needed per iteration with the current implementation.
>>
>> It would also make the loop tighter as upon entering the loop (after first
>> conditional evaluation), one less opcode remains relevant to the loop.
>>
>> An analogous approach can be taken for the for-loop.
>>
>> Thanks,
>>
>> Ben
>>
>> PS: This is my first post on a PHP mailinglist - I am very excited! :)
>>
>> --
>>
>> Benjamin Coutu
>> Zeyon Technologies Inc.
>> http://www.zeyos.com
>>
>>
>> --
>> PHP Internals - PHP Runtime Development Mailing List
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>



-- 
Xinchen Hui
@Laruence
http://www.laruence.com/

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to