Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111865 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 8348 invoked from network); 15 Sep 2020 14:43:08 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 15 Sep 2020 14:43:08 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D858E1804B7 for ; Tue, 15 Sep 2020 06:51:16 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,FREEMAIL_REPLY, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 15 Sep 2020 06:51:16 -0700 (PDT) Received: by mail-lf1-f47.google.com with SMTP id z17so3144062lfi.12 for ; Tue, 15 Sep 2020 06:51:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=alHqHf+37HaVcraqNr4PsZTp0mBlfHtHJmLGZR3q+MU=; b=MjnyWlj1qigxSvvLPd6EB60W2w6i6KepffVcNpLlgkRDARLMQQnK9QfSsXvy6/pEHm d0AQfHWDhAPz7rI7ntUwtpQAW7rKShUOnBh4Wd3T2U3UJI1tGFtX4OSDk4FbjHQsWrtD usJUSK8G5methL3m80Hh0Iz1gONYaH5jU03iIFWlRv9OAyjTGs964ZEp0UMN/1vW/5JU 7f3thgE/y4Fv5YMZvutssm615uai1g3YxbOOQ7hUkDBGq+YynyARdRCxlKmkdmIuodZq BxISq6iuPc4B5MICbWY1EgCB0UJtiENKnM8VFiwDP3mKuvwM3jxHARwjUnnloMoZV1Us CQqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=alHqHf+37HaVcraqNr4PsZTp0mBlfHtHJmLGZR3q+MU=; b=oa2nUW6qKh4bDhbtW/OWuSizyVBwQf1ngTGHn8FdB/w0+SJ7zUTGMroI/ce0PePm/O VlrYSncbzFV6l1goddSWb8GfECnCX9n9/BHsPsKds1VtPwndqEdV+Lm4ECTm51yk7mj2 Pdgdz39KA6Q4MLdEbpyeXhZlSEsGhz+QicajZ1m9/cFtHIV4rcKDslz/IGhvmeDs1bX/ gA3p+FPt/lTJUJHmquPx+7egyzGlqWpOELJviMlowjc2SxPwpB1AzM3S8YEoN0kIgl72 C6qbF9OUTY7vZFu/ncOl0SwsxVNK71eLluRwwAdvtVoghklcOLsehoUe2q/dSUvuC37z 1zmw== X-Gm-Message-State: AOAM531ymjAg9c0q6WSXMH9/LCF87hmCRwJ5rKMFLDW7e7jQBmYaggyI SzL0Er+RQEKYsP+ximzUnaSFESYwaCDN6nlP43Q= X-Google-Smtp-Source: ABdhPJyb0Fi3TbkAUGnRL87vv4nOs7+/M+I+UnCVTw9DDwPRqEQELivq7obv/9+YerD7TvlSET3emKAkkhAngBGHCEc= X-Received: by 2002:a19:3d4:: with SMTP id 203mr5326408lfd.526.1600177873090; Tue, 15 Sep 2020 06:51:13 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 15 Sep 2020 16:50:56 +0300 Message-ID: To: Chase Peeler Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000b3fd2505af5a71d2" Subject: Re: [PHP-DEV] Compiler Optimizations From: benas.molis.iml@gmail.com (Benas IML) --000000000000b3fd2505af5a71d2 Content-Type: text/plain; charset="UTF-8" Ah, sorry! Misread your post. Anyways, the compiler doesn't transform `\array_keys()` yet, so there's no optimization for that. As for other compiler optimizations, 2 that I know that the compiler does is: 1. Binary OP evaluation i. e. `2 * 2` does not yield `ZEND_ADD` opcode but is instead computed by the compiler directly. 2. There are special functions that have their own opcodes. You can learn more about those here: https://phpinternals.net/articles/optimising_internal_functions_via_new_opcode_instructions Best regards, Benas On Tue, Sep 15, 2020, 4:44 PM Chase Peeler wrote: > I wasn't proposing that my example be supported. I'm totally okay with the > fact that it doesn't. My question was about whether or not those kinds of > optimizations are documented anywhere so that developers can make sure they > don't miss out on them by not fitting the proper pattern. > > On Tue, Sep 15, 2020 at 9:40 AM Benas IML > wrote: > >> Hey, >> >> During my free time, I'm implementing that specific `array_keys` >> optimization. I'm not planning on supporting cases like yours (i. e. >> indirection through a variable) since there's no point in doing that. And >> also, it's not feasible to support every use case. Should we also support >> cases like this? >> >> ```php >> $a = 'array_keys'; >> $b = $a(...); >> $c = 'b'; >> >> foreach ($$c as $key) { >> ... >> } >> ``` >> >> Obviously not. `\array_keys` optimization will work the same way as an >> optimized `strlen` function works. >> >> That means that the optimization is only going to be applied if the >> `array_keys` function is used directly in the `foreach` loop and only if a) >> either the namespace is global b) or `\array_keys(...)`/`use function >> array_keys` is used. >> >> >> Best regards, >> Benas >> >> On Tue, Sep 15, 2020, 4:23 PM Chase Peeler wrote: >> >>> I brought this up on another thread, but it wasn't addressed (which is >>> fine, since it was somewhat off-topic). I thought it might be >>> worth bringing up in its own thread, though. >>> >>> In the other thread, someone had mentioned the following compiler >>> optimization >>> >>> foreach(\array_keys($arr) as $key) { >>> >>> and quietly transform that into: >>> >>> foreach ($arr as $key => >>> $_unusedVariableNameThatIsntEvenSpilledToTheScope) >>> { >>> >>> I would be more likely to write: >>> $keys = array_keys($arr); >>> foreach($keys as $key){ >>> Which would prevent me from being able to take advantage of the >>> optimization. >>> >>> So, what I was wondering, is if there are other optimizations I might be >>> missing out on, and if so, are they documented anywhere? >>> >>> >>> -- >>> Chase Peeler >>> chasepeeler@gmail.com >>> >> > > -- > Chase Peeler > chasepeeler@gmail.com > --000000000000b3fd2505af5a71d2--