Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:67967 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 87985 invoked from network); 27 Jun 2013 16:21:17 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Jun 2013 16:21:16 -0000 Authentication-Results: pb1.pair.com header.from=laruence@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=laruence@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.45 as permitted sender) X-PHP-List-Original-Sender: laruence@gmail.com X-Host-Fingerprint: 209.85.215.45 mail-la0-f45.google.com Received: from [209.85.215.45] ([209.85.215.45:45626] helo=mail-la0-f45.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E0/4B-34034-A766CC15 for ; Thu, 27 Jun 2013 12:21:15 -0400 Received: by mail-la0-f45.google.com with SMTP id fr10so1069919lab.18 for ; Thu, 27 Jun 2013 09:21:11 -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=fhGEqYN+UUmidU9j8TGpODbmEsmUirOvdf1NOo6oawI=; b=N8+duoKclJyS3ouaRT4rnxClK0uz75qFw73EpCaQ619ErbzhYzOUQRcN+shfhCXlBd xMw/iFpGQzk7YJLfnDJue2B32NttbFV2MERZp9lodAmQCiUBFN2rlbqhJT9jYYbxHXqp CK2YEd/UBANR3fKpQyDOFKxLZRKAqNxpEI8ccYQOXtZ1OC4RNdoXG8Ev34JPgQS7wZVJ HkNw7XsDuit/zmCLgIWEOf+pq1o02TS8b1MkPGVJLu6Rpn8x+Q5FN64gT0TjI0Jkb871 dmBoUDCEihh3TJO6/ei4l+XBZpiLaULbU/q+cfDUFv1tjOnQphzkOfvd102ubnu+a0pG JCYg== X-Received: by 10.152.27.195 with SMTP id v3mr4509366lag.73.1372350071223; Thu, 27 Jun 2013 09:21:11 -0700 (PDT) MIME-Version: 1.0 Sender: laruence@gmail.com Received: by 10.114.29.36 with HTTP; Thu, 27 Jun 2013 09:20:51 -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:20:51 +0800 X-Google-Sender-Auth: LXmb0aGS1Pe4q-ByC8307-_1kC0 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 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.... thanks > > Anthony -- Laruence Xinchen Hui http://www.laruence.com/