Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:84472 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 79376 invoked from network); 9 Mar 2015 13:43:37 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Mar 2015 13:43:37 -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.177 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 209.85.220.177 mail-vc0-f177.google.com Received: from [209.85.220.177] ([209.85.220.177:39076] helo=mail-vc0-f177.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A0/00-29848-D3D9DF45 for ; Mon, 09 Mar 2015 08:16:46 -0500 Received: by mail-vc0-f177.google.com with SMTP id id10so9698191vcb.8 for ; Mon, 09 Mar 2015 06:16:43 -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=uWEGrByQfa2BY1QihSVX1uJHrwK1zz9XhqGQ0i8JpF4=; b=OnWsy67//M4Q3/QhbQgXyRjVkVywO0FyqQ1JrrNLtW+YVTTXxBbDfzYjf6EHW5eox3 0nDpHG6d/9cKNNoR7FisthIwMsKXBe2OZLpEsuUInGTnesP1U2u8GIjTHdICMm+h2lpn q5pQ7DU7CwcnSCtqz6FKyLITkuPbAmDAJpQLqlMHUipnsA+tlBdOFNVePzArdR+4glVK GIw2pcuPGcHnC2WlIZyizTEQCxeDPcGNuXwegMxM1IJziUis3Awi5GoQv5eZEeJCMBWL v7dLF0VapDc0/VaVgi64nsuY8bCiEccdPExM3SZKK9J8UuIS0VSgOfFoJtwlGEEAaahp +xHw== X-Gm-Message-State: ALoCoQnGY/gvWAOfGbzNyOY/0bQLMWxGbdNzo0qARMmjtmSzl3kCHGdknIjACyEPPWkhmOqAUDp/dF2dyRauv13iZZ56dIm+L9s9bl7fNCpj9O3kDt/wdZDSHam+WJ+eWyP1fFwS+kUnDNsezS+Z71gLhtkOXnJfOA== MIME-Version: 1.0 X-Received: by 10.52.165.97 with SMTP id yx1mr14109895vdb.5.1425907003117; Mon, 09 Mar 2015 06:16:43 -0700 (PDT) Received: by 10.52.113.231 with HTTP; Mon, 9 Mar 2015 06:16:42 -0700 (PDT) In-Reply-To: References: Date: Mon, 9 Mar 2015 16:16:42 +0300 Message-ID: To: Bob Weinand Cc: Derick Rethans , Xinchen Hui , PHP Internals Content-Type: multipart/alternative; boundary=001a11c28bec6762410510dad887 Subject: Re: [PHP-DEV] About optimization for compiler From: dmitry@zend.com (Dmitry Stogov) --001a11c28bec6762410510dad887 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Mon, Mar 9, 2015 at 3:52 PM, Bob Weinand wrote: > > Am 09.03.2015 um 11:24 schrieb Derick Rethans : > > > > On Fri, 27 Feb 2015, Xinchen Hui wrote: > > > >> Hey Internals: > >> > >> I was looking Bob's switch optimization.. > >> > >> then I start to worry about where is the place optimization shoul= d > goes.. > >> > >> in generally, PHP is a interpreted language. IMO, it should > >> compiler the PHP codes to opcode without any optimization(of course, > >> we did some, but they won't change a lots of opcodes which should be > >> generated).. > >> > >> and, since 5.5, we already have opcache bundled in.. > >> > >> thus, I am proposing a principle, that is: > >> > >> in the future, we only do optimization in opcache side, and keep > >> Zend Compiler without any optimization... considering Zend Compiler do > >> things in -O0. > >> > >> since, optimization always are dangerous.. if we only do them in > >> opcache, user can still run them codes with disable opcache, or at > >> least disable some optimization level which cause that.. > >> > >> what do you think? > > > > I think it's a very sensible approach. I would however like to see this > > sort of 'experimental' optimisations to be also possible through an > > extension. I think some of Sara's? AST hooks might help here? > > > > cheers, > > Derick > > Hey Derick, > > I don't think this would work. The AST hooks allow changing the AST, but > they wouldn't allow emitting opcodes based on AST. > (We can manipulate the AST, but we can't substitute the function which > compiles e.g. a switch-AST / zend_compile_switch) > > The only thing which would work here is changing the opcodes after the > compilation, but that's a hack. That's going to opcache way and implies > that we have to do a) full-op_array walks and b) messing around with > jump-offsets. > Also, when we do this in an ext, we must assume that we don't run this an= d > opcache simultaneously etc. (because opcache relies on ZEND_SWITCH opcode > to *not* exist and the ext would have to rely on the specific order in > which instructions are emitted by the compiler) > > The way I did it here is IMO the only clean way to do it. Feel free to > prove me wrong, though ;-) > I think if we can implement efficient ZEND_SWITCH in ZE and it provides some gain, we should do it there. I know some other languages use similar instruction (Prolog WAP uses switch_on_...), but the semantic there is more clear. In php we have to care about NULL, FALSE, TRUE and conversion to INT and STRING. May be it's possible to simplify this limiting the usage by cases when only numbers and non-numeric strings are used. Then we could use more clear and efficient ZEND_SWITCH_LONG and ZEND_SWITCH_STRING. Thanks. Dmitry, > > =E2=80=A6 > > Also, we could do the optimization only in opcache, but this really > wouldn't ease integration of this particular optimization... > I'd rather like to see specific optimizations very close to the Engine > also in the Engine or in some subdirectory of Zend. Instead of an ext. > Releases anyway already are dependent on opcache keeping up with the engi= ne. > > Bob --001a11c28bec6762410510dad887--