Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111863 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 4832 invoked from network); 15 Sep 2020 14:32:12 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 15 Sep 2020 14:32:12 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E5B55180532 for ; Tue, 15 Sep 2020 06:40:21 -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-lj1-f175.google.com (mail-lj1-f175.google.com [209.85.208.175]) (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:40:21 -0700 (PDT) Received: by mail-lj1-f175.google.com with SMTP id k25so2848079ljg.9 for ; Tue, 15 Sep 2020 06:40:21 -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=WxjUfOHO+kfVbsGo3xGNMMcEry2nR8GsFL2ug+OTxnU=; b=QjTzVipUlrjuQzu7pJ8+ZKAzvB7K/4Zhkpl6HHOckvZz11Q2ldhrWxEQczLDgERLds nVsU5UOp5+IjX4kzZhOYbM6z/JlbLazPicIf1C1V4QdbyVnrhuSnKy/pndaRv6vCgOGD dX1MbtrZy5LOUKSEw6fC6p1iAihg5TdsDqWfcgFaBU32rFUC1bOuY98KaflIijrkb5Hm WE/KJ/CNu37jSPznmO8gt+aFGJc9P0aPlqte2hYDO/wekSoom3LlU4XOUI0GvEZ74nOU pk+IP6zZrGJWND/gulqGLGIO0dSi8pQOPyfXn6pcS7MXGsXAwYJ4QL+xe6AUXPc61za3 FxpA== 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=WxjUfOHO+kfVbsGo3xGNMMcEry2nR8GsFL2ug+OTxnU=; b=nMTzUjVVe420Ml4eyiS5atUoVbk7neMCS2hayEjLdsrpJXmcYp7eSmjDP1uUKY+AFc m19RpZxDwKDqLKuGFhXLw0Q3KYdqxPANx4ywiGrgItPmNBjyRnoTOPNQuDBbJBv0bIcH xCaEecrpWs1TFWAQMu0PhlZovwjDOkg1Yy1tHN47u6qIz533VUxITOvzeY2Z8lisFIDE BR4lQw+e/nfWm9Yl6tfutSG6YjIbJGt1deBi6TQjD/xZCjDyHE+QGUMEsQ5f09shpaub lBSBBgDjMHEOw2DcGPBW6J9luQo4f9BLujfmWUqdqHGc9XAmatJaRVOcZiD9c8vcqFan mgYA== X-Gm-Message-State: AOAM531QSuw3LKWCJCvaNMgfhelU7UN1iSD6smyf5tpGmCOjj80Wwii9 YIM7pzPSoDR1nDH4n3BKyc/FDcaomxWXbvx7XvQ= X-Google-Smtp-Source: ABdhPJzg9XOuPkzMVn+jpTTkQ2gPJ9qZK5dd2ABP+hDXJTn03rSBODZbyw2wJCbUujE2ut+VkycKSOQrlgEg3KrvQTM= X-Received: by 2002:a05:651c:1392:: with SMTP id k18mr6746849ljb.445.1600177217438; Tue, 15 Sep 2020 06:40:17 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 15 Sep 2020 16:40:05 +0300 Message-ID: To: Chase Peeler Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000009f88dd05af5a4a72" Subject: Re: [PHP-DEV] Compiler Optimizations From: benas.molis.iml@gmail.com (Benas IML) --0000000000009f88dd05af5a4a72 Content-Type: text/plain; charset="UTF-8" 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 > --0000000000009f88dd05af5a4a72--