Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:76436 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 51373 invoked from network); 11 Aug 2014 19:07:02 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Aug 2014 19:07:02 -0000 Authentication-Results: pb1.pair.com header.from=dmitry@zend.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=dmitry@zend.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 209.85.220.180 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 209.85.220.180 mail-vc0-f180.google.com Received: from [209.85.220.180] ([209.85.220.180:37037] helo=mail-vc0-f180.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BC/54-22956-35419E35 for ; Mon, 11 Aug 2014 15:07:00 -0400 Received: by mail-vc0-f180.google.com with SMTP id ij19so12026121vcb.39 for ; Mon, 11 Aug 2014 12:07:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=SgIfRcUJ0CK1SoBEv8i2xrVnFPAm1AmWnFKQAsLtJaE=; b=awjULlG5OcW0jia6J3rnwVO+a4atYm2TQYoSWpncmiO/CxLv6YO0krIhnnDUmn+v05 3WzlAKtu3ACu+GfcFR24//UY6xJ5gyOVhd3R8ys9z4fPuUxP1zTPicnZ70pjeAxJQKOK l2pV2QU5OVtZ9+698o8fDa+3/HLmM6tl8+98k7tL6mS1BSHWLhk8gQQC8yommgn6A0iW HcaSIngahJ4a2R6rmkNCo2Uoks+BSgJ/YAJOC+A2Gx9qXT41SqsYHSnR8zCueLrGTCpG a35pQrEpE8TXR2VIq1eFlTtGWKSEYDJfNepTzUNRI11llHe641jeC3Abz1WE4woXi2Mq 0G1g== X-Gm-Message-State: ALoCoQkrkwoNBzNqE2zc4iMNayHFN3rgDaL4o/j4T+HCoVXwxqY43FSfwyHTDJ5BGhs4YyxzHI/AlzJ+JlleG9gaPzl+2W4Do9g2oc2bXruH3vBXcoJs81MWu6nJS03l/T5QujBFfoBk MIME-Version: 1.0 X-Received: by 10.221.44.69 with SMTP id uf5mr37827320vcb.4.1407784058311; Mon, 11 Aug 2014 12:07:38 -0700 (PDT) Received: by 10.52.110.170 with HTTP; Mon, 11 Aug 2014 12:07:38 -0700 (PDT) In-Reply-To: References: Date: Mon, 11 Aug 2014 23:07:38 +0400 Message-ID: To: Andrea Faulds Cc: PHP internals Content-Type: multipart/alternative; boundary=001a11339e88b769a605005f4494 Subject: Re: [PHP-DEV] [RFC] Closure::call and Function Referencing as Closures From: dmitry@zend.com (Dmitry Stogov) --001a11339e88b769a605005f4494 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Mon, Aug 11, 2014 at 10:09 PM, Andrea Faulds wrote: > > On 11 Aug 2014, at 08:36, Dmitry Stogov wrote: > > > Hi Andrea, > > > > Could you measure the performance impact of function referencing. > > > > > $func =3D "strlen"; > > for ($i =3D 0; $i < 10000; $i++) { > > $func("hello"); > > } > > ?> > > > > vs > > > > > $func =3D &strlen; > > for ($i =3D 0; $i < 10000; $i++) { > > $func("hello"); > > } > > ?> > > On my machine: > > andreas-air:php-src ajf$ time sapi/cli/php ../funcref_a.php > > real 0m0.043s > user 0m0.022s > sys 0m0.008s > > andreas-air:php-src ajf$ time sapi/cli/php ../funcref_b.php > > real 0m0.023s > user 0m0.015s > sys 0m0.006s > > I think the reason that function references are faster here is that it > only has to do the hash table lookup once. If you tried to create a > reference on each iteration and compared that to just using the string, > then the string would be faster, as no memory needs to be allocated and > deallocated for the closure. > > > I don't like the "&" syntax a lot, but I understand that it's a > compromise between readability and implementation complication. > > Right. Myself, I=E2=80=99d prefer to just merge PHP=E2=80=99s namespaces = and have $foo =3D > func_name; work, but that wouldn=E2=80=99t work well and would break a lo= t of > things. > may be: $a =3D function strlen; or $a =3D function(stren); but these are not excellent as well :( > > > > The patch probably misses support for "&self::foo", "&parent::foo", > "&static::foo=E2=80=9D. > > Good catch, I=E2=80=99ll try and get that implemented. Actually, I wonder= if > having &self::foo be bound to the object using it would be a good idea. > While I resisted for &$foo::bar (I don=E2=80=99t support that syntax anyw= ay), there > might be some merit in it after all. If it would bind for you, you could > always remove the binding or change it if it would be a problem. > > > It also may be improved using run_time cache (this is not important now= ). > > That=E2=80=99s something I wanted to do (might solve the performance prob= lems with > using & on each iteration), but I=E2=80=99m not sure quite what the right= way to > implement that is. In particular, what kind of cache (some sort of hash > map?), how to index it (function name? fully-qualified function name?) an= d > where to put it. I suppose I could just add a zval pointer to zend_functi= on > itself, but that would add eight bytes to every single function, which > would add up. > > Actually, on a related note: Currently & creates a new closure on each > use, and in PHP closures are compared by identity, not by their value. > Perhaps we should change that so it checks for the same scope, this_ptr a= nd > implementation? Having &strlen =3D=3D=3D &strlen would probably be a good= thing, > it=E2=80=99s the more intuitive thing at least. Comparing the this_ptr of= the two > would be easy, however I have no idea whether you could compare the two > zend_functions and have it work properly. You can=E2=80=99t just do an = =3D=3D in the C > code, as closures embed and modify the zend_function. > I may implement this part if the RFC will be accepted. Actually, most of the code may be just copy-pasted from ZEND_INIT_STATIC_METHOD_CALL. Thanks. Dmitry. > -- > Andrea Faulds > http://ajf.me/ > > > > > --001a11339e88b769a605005f4494--