Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:67964 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 83024 invoked from network); 27 Jun 2013 15:54:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Jun 2013 15:54:25 -0000 Authentication-Results: pb1.pair.com smtp.mail=ircmaxell@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ircmaxell@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.42 as permitted sender) X-PHP-List-Original-Sender: ircmaxell@gmail.com X-Host-Fingerprint: 209.85.212.42 mail-vb0-f42.google.com Received: from [209.85.212.42] ([209.85.212.42:48325] helo=mail-vb0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 96/3A-34034-0306CC15 for ; Thu, 27 Jun 2013 11:54:25 -0400 Received: by mail-vb0-f42.google.com with SMTP id i3so802880vbh.15 for ; Thu, 27 Jun 2013 08:54:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=ghSZm15bLOO9P3x6Xf3mX07ae+gYgZhbBFE+jVtrpAI=; b=Kw7G7AhHuLkTf1g1/1zD59tjZ9yq7mrdmhhohRV7PmggzivVbQ1FWnOgJzHwYVlDlS YjTJH6QOHa18IkPSMuCmE9GvSITa7iFa+g6uDYsrYB5Jarsf6XWLcNwJxgKBUr3TUfJI EEEHDDQTZz5uflAJra8ogE6yeUxM7T8p8veVQso234s27QURpfejV7cyAWVQEEnoN0jk hxWqyrY/RGdVKxY+ZFw9ebe6zSgiYC8P/s/HTkVl+JAy9c4qOwGfr4Jml8yRge2V/oG5 lwzltFoeOL5YggMWlRHNk4CRmtOvwo8t8Dd2k2MrBC84EfFyq1J9gCLbZb31bGHJBk0v 6Ayw== MIME-Version: 1.0 X-Received: by 10.220.191.5 with SMTP id dk5mr3740157vcb.47.1372348462339; Thu, 27 Jun 2013 08:54:22 -0700 (PDT) Received: by 10.58.94.201 with HTTP; Thu, 27 Jun 2013 08:54:22 -0700 (PDT) In-Reply-To: References: <51C9FA9C.8050403@sugarcrm.com> <51CA1C93.6080500@sugarcrm.com> <51CA24C5.9090505@sugarcrm.com> <51CB167A.4020207@sugarcrm.com> Date: Thu, 27 Jun 2013 11:54:22 -0400 Message-ID: To: Laruence Cc: Stas Malyshev , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001a11c1bfaa9b1e7f04e024c6bb Subject: Re: [PHP-DEV] RFC: Protocol Type Hinting From: ircmaxell@gmail.com (Anthony Ferrara) --001a11c1bfaa9b1e7f04e024c6bb Content-Type: text/plain; charset=ISO-8859-1 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... Anthony --001a11c1bfaa9b1e7f04e024c6bb--