Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:67969 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 90554 invoked from network); 27 Jun 2013 16:30:48 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Jun 2013 16:30:48 -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.215.53 as permitted sender) X-PHP-List-Original-Sender: laruence@gmail.com X-Host-Fingerprint: 209.85.215.53 mail-la0-f53.google.com Received: from [209.85.215.53] ([209.85.215.53:60018] helo=mail-la0-f53.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 65/CB-34034-7B86CC15 for ; Thu, 27 Jun 2013 12:30:48 -0400 Received: by mail-la0-f53.google.com with SMTP id fs12so1066893lab.40 for ; Thu, 27 Jun 2013 09:30:44 -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=bCgj+ep5Bn/qO3BfRdweofJWZUuloOhL5fAJshmXCoU=; b=XGx14iXCgzBjf72AR3UFbGft26xL5dp1C5Cvh3tk607Je/JAnZSg4iM1MxBeT4WvaI 8qIiv6RaDG5LrsYVHbcWnHiKOhsuYLNntjI9nJgGT6Oc6rBMcMoY7SiixWHWLVzZREZ4 fdhr3/uZiVmy01/j5VHUy130tBhqw6Noi8RR0psO7TpoWPpzwwlbaAmke2HorKoQdhUD 3EKesYzrxQqpCAUDeyFTA7z+KFwwSqX4BsxxtZNTmnO4JnErMv0i5R5WLyc0owixVEbF dw604oWXw7K9wpFDbk0zH8viU5uLVLKMelC4ppMlxBQu4pf2C5f4rP4JsrLQ11url3Dx 2DBA== X-Received: by 10.152.21.99 with SMTP id u3mr4671094lae.18.1372350644299; Thu, 27 Jun 2013 09:30:44 -0700 (PDT) MIME-Version: 1.0 Sender: laruence@gmail.com Received: by 10.114.29.36 with HTTP; Thu, 27 Jun 2013 09:30:24 -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:30:24 +0800 X-Google-Sender-Auth: gMe36TYMl8SFHNUhz8C58Ed8Hrk 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: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 ... thanks > thanks > >> >> Anthony > > > > -- > Laruence Xinchen Hui > http://www.laruence.com/ -- Laruence Xinchen Hui http://www.laruence.com/