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....

thanks

>
> Anthony



--
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