Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:67972 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 95547 invoked from network); 27 Jun 2013 16:40:37 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Jun 2013 16:40:37 -0000 Authentication-Results: pb1.pair.com smtp.mail=laruence@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=laruence@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.173 as permitted sender) X-PHP-List-Original-Sender: laruence@gmail.com X-Host-Fingerprint: 209.85.217.173 mail-lb0-f173.google.com Received: from [209.85.217.173] ([209.85.217.173:60715] helo=mail-lb0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BF/EC-34034-40B6CC15 for ; Thu, 27 Jun 2013 12:40:37 -0400 Received: by mail-lb0-f173.google.com with SMTP id v1so530535lbd.18 for ; Thu, 27 Jun 2013 09:40:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type; bh=bumam/Go6OOG5Ft388xY1ZX3na3YZUVFn92bDFuK6T0=; b=jUwZzeiZgMG9yhl1/IJKESgvx3rEPmV7m3hPBwQKa1ooIIei38vxD55E1206x88i1F +MFwPKHeb+dfOq4wEOvHx+ZVStfCZlBFJuaT13tgtKWz6jpAjb9hirY7KF5VxbOYtP6X QflQTltJeJHY/Lox0YgJmdm9+UGtjKxMutLylmYc/Y1WH35KVZbfUqCYZJj+NxQESsYv HjR4bGC2X6XvCITnNDdOHROBxtbsnN8XV0kv/E/AokcOphsibW9ONQCtkg0okYeVsTVg fIbKM1wVx1c1/2GbI81cPMwcpnkCVSWs2yNFP6KC1aI6+05EctN9LCeSCXAG64TcLk2b aOlQ== X-Received: by 10.112.150.170 with SMTP id uj10mr4546185lbb.93.1372351233094; Thu, 27 Jun 2013 09:40:33 -0700 (PDT) MIME-Version: 1.0 Sender: laruence@gmail.com Received: by 10.114.29.36 with HTTP; Thu, 27 Jun 2013 09:40:12 -0700 (PDT) In-Reply-To: References: <51C9FA9C.8050403@sugarcrm.com> <51CA1C93.6080500@sugarcrm.com> <51CA24C5.9090505@sugarcrm.com> <51CB167A.4020207@sugarcrm.com> Date: Fri, 28 Jun 2013 00:40:12 +0800 X-Google-Sender-Auth: o5mawYudzxctfnqWo2DCH-xi3NA Message-ID: To: Anthony Ferrara Cc: Stas Malyshev , "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] RFC: Protocol Type Hinting From: laruence@php.net (Laruence) On Fri, Jun 28, 2013 at 12:30 AM, Laruence wrote: > On Fri, Jun 28, 2013 at 12:20 AM, Laruence wrote: >> On Thu, Jun 27, 2013 at 11:54 PM, Anthony Ferrara 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/