On Fri, Jun 28, 2013 at 12:30 AM, Laruence <larue...@php.net> wrote:
> On Fri, Jun 28, 2013 at 12:20 AM, Laruence <larue...@php.net> wrote:
>> On Thu, Jun 27, 2013 at 11:54 PM, Anthony Ferrara <ircmax...@gmail.com> 
>> wrote:
>>> Laruence,
>>>
>>>> so are you saying, that check every method's signature of a class is
>>>> *faster* than just check interface?
>>>
>>>
>>> Yes, yes I am saying that. And yes, the numbers show that.
>>>
>>> Think about it for a second. When you implement an interface, at compile
>>> time the compiler must loop through and check every methods signature for
>>> every interface. No matter if you ever type-hint against that interface or
>>> not. It always runs every class definition. And due to the point that opcode
>>> caches aren't caching this compilation step, it happens on every page load.
>>>
>>> So in the case where you implement an interface, but don't actually use that
>>> interface in any hints, you're still iterating through every method.
>>>
>>> My case only iterates through those methods when the hint is actually
>>> reached. So in the cases where the class never enters a hinted
>>> function/method, you wind up saving that iteration. So in that case it's
>>> significantly faster...
>>>
>>> In the case where both happens, all this does is delay the loop until
>>> run-time. So the iteration still happens (the same amount, as it happens for
>>> every unique class:interface pairing possible). In fact, the comparison is
>>> quite comparable (there are some minor differences, but not in terms of
>>> what's happening, just when it's happening).
>>>
>>> And once we have a comparison (successful or not), we cache it for the two
>>> class_entries involved. So then we never have to worry about executing it
>>> again.
>>>
>>> Therefore, structural hinting will be *worst-case* the same cost
>>> (statistically) as interfaces (it's just delaying the check to runtime
>>> instead of *every* compile). The average case (a cache hit, multiple checks
>>> of the same CE), structural will be faster as it's just a HT lookup instead
>>> of a recursive instanceof mapping. The best case (no hint), you *never*
>>> iterate through the methods in the first place.
>>>
>>> Sounds like a pretty convincing win on performance to me... Which is why
>>> it's kind of weird to keep hearing that it's slow to do, at least 6 times
>>> now in this thread...
>>
>>>
>>>> I don't need to run the test at all
>>>
>>>
>>> sigh...
>> sigh, you made me to do the thing I really don't want to do, pull,
>> config, make ....
>>
>> but fine...
>>
>> $ uname -a
>> Darwin Laruence-Macbook.local 12.3.0 Darwin Kernel Version 12.3.0: Sun
>> Jan  6 22:37:10 PST 2013; root:xnu-2050.22.13~1/RELEASE_X86_64 x86_64
>>
>>
>> here is my test agianst your patch,  for 3 times:
>>
>> [Laruence@localhost:/Users/Laruence/opensource/trunk/]
>> $ sapi/cli/php /tmp/1.php
>> Interface in 0.58958697319031 seconds, 5.8958697319031E-7 seconds per run
>> Structural in 0.57371211051941 seconds, 5.7371211051941E-7 seconds per run
>> Native in 0.34867691993713 seconds, 3.4867691993713E-7 seconds per run
>> [Laruence@localhost:/Users/Laruence/opensource/trunk/]
>> $ sapi/cli/php /tmp/1.php
>> Interface in 0.57501292228699 seconds, 5.7501292228699E-7 seconds per run
>> Structural in 0.58277201652527 seconds, 5.8277201652527E-7 seconds per run
>> Native in 0.33706784248352 seconds, 3.3706784248352E-7 seconds per run
>> [Laruence@localhost:/Users/Laruence/opensource/trunk/]
>> $ sapi/cli/php /tmp/1.php
>> Interface in 0.55554509162903 seconds, 5.5554509162903E-7 seconds per run
>> Structural in 0.59201097488403 seconds, 5.9201097488403E-7 seconds per run
>> Native in 0.34463691711426 seconds, 3.4463691711426E-7 seconds per run
>>
>> as you can see, it only win one time!!!
>>
>> and after that,  a more reallife like test I made, you can find it
>> here:https://gist.github.com/laruence/5877870
>>
>> run 3 times:
>> $ sapi/cli/php /tmp/2.php
>> Interface in 0.53591203689575 seconds, 5.3591203689575E-7 seconds per run
>> Structural in 0.58459782600403 seconds, 5.8459782600403E-7 seconds per run
>> Native in 0.34605598449707 seconds, 3.4605598449707E-7 seconds per run
>> [Laruence@localhost:/Users/Laruence/opensource/trunk/]
>> $ sapi/cli/php /tmp/2.php
>> Interface in 0.55550718307495 seconds, 5.5550718307495E-7 seconds per run
>> Structural in 0.59183287620544 seconds, 5.9183287620544E-7 seconds per run
>> Native in 0.35443592071533 seconds, 3.5443592071533E-7 seconds per run
>> [Laruence@localhost:/Users/Laruence/opensource/trunk/]
>> $ sapi/cli/php /tmp/2.php
>> Interface in 0.5577380657196 seconds, 5.577380657196E-7 seconds per run
>> Structural in 0.56625699996948 seconds, 5.6625699996948E-7 seconds per run
>> Native in 0.36081981658936 seconds, 3.6081981658936E-7 seconds per run
>>
>>
>> it never won once! and there will be lots' of classes in reallife
>> applications, you cache hashtable will resize... it will make thing
>> worse..
>>
>>
>> and at last, I clarified again, it's not the main reason for me to
>> agianst it....
>>
>
> previous test script only measure the last all, although that,
> interface already won with complex arguments signatures...
>
> here is a fixed one: https://gist.github.com/laruence/5877928
>
> run 3 times:
>
> $ sapi/cli/php /tmp/2.php
> Interface in 1.7314801216125 seconds, 1.7314801216125E-6 seconds per run
> Structural in 1.7587349414825 seconds, 1.7587349414825E-6 seconds per run
> Native in 1.0431759357452 seconds, 1.0431759357452E-6 seconds per run
> [Laruence@localhost:/Users/Laruence/opensource/trunk/]
> $ sapi/cli/php /tmp/2.php
> Interface in 1.7132070064545 seconds, 1.7132070064545E-6 seconds per run
> Structural in 1.7542362213135 seconds, 1.7542362213135E-6 seconds per run
> Native in 1.0379688739777 seconds, 1.0379688739777E-6 seconds per run
> [Laruence@localhost:/Users/Laruence/opensource/trunk/]
> $ sapi/cli/php /tmp/2.php
> Interface in 1.6947190761566 seconds, 1.6947190761566E-6 seconds per run
> Structural in 1.7611300945282 seconds, 1.7611300945282E-6 seconds per run
> Native in 1.04856300354 seconds, 1.04856300354E-6 seconds per run
>
>
> as you can see, still, your patch won zero ...

okey, you said I was run in debug-mode, here is my new configure:

$ cat ./config.nice
#! /bin/sh
#
# Created by configure

'./configure' \
'--enable-opcache' \
"$@"

and run 3 times:

$ sapi/cli/php /tmp/2.php
Interface in 0.77343797683716 seconds, 7.7343797683716E-7 seconds per run
Structural in 0.79890298843384 seconds, 7.9890298843384E-7 seconds per run
Native in 0.46520400047302 seconds, 4.6520400047302E-7 seconds per run
[Laruence@localhost:/Users/Laruence/opensource/trunk/]
$ sapi/cli/php /tmp/2.php
Interface in 0.90446901321411 seconds, 9.0446901321411E-7 seconds per run
Structural in 0.95593690872192 seconds, 9.5593690872192E-7 seconds per run
Native in 0.57916212081909 seconds, 5.7916212081909E-7 seconds per run
[Laruence@localhost:/Users/Laruence/opensource/trunk/]
$ sapi/cli/php /tmp/2.php
Interface in 0.73255109786987 seconds, 7.3255109786987E-7 seconds per run
Structural in 0.79073309898376 seconds, 7.9073309898376E-7 seconds per run
Native in 0.46475696563721 seconds, 4.6475696563721E-7 seconds per run

I believe, the more classes there are, the slower your patch will be.


thanks

>
>
>
> thanks
>> thanks
>>
>>>
>>> Anthony
>>
>>
>>
>> --
>> Laruence  Xinchen Hui
>> http://www.laruence.com/
>
>
>
> --
> Laruence  Xinchen Hui
> http://www.laruence.com/



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

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

Reply via email to