Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111864 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 6642 invoked from network); 15 Sep 2020 14:36:35 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 15 Sep 2020 14:36:35 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id EFF001804B8 for ; Tue, 15 Sep 2020 06:44:44 -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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,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-vs1-f44.google.com (mail-vs1-f44.google.com [209.85.217.44]) (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:44:44 -0700 (PDT) Received: by mail-vs1-f44.google.com with SMTP id j3so1950573vsm.0 for ; Tue, 15 Sep 2020 06:44:44 -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=wI/fgkpfkM5obyK74TmNHrNP580D/KMa6vQsaGeQQqI=; b=NzOwPdeAalXMjbBdfBvV2lNzogGj8+jbGGzNV/CZvxjFc9rPPHkPzXsIfvYeEvF1Vo pxKTIKXgzP8BAkWzu0hn5qWYL3WJfVkVA4zT0uIypqXuV6Zw9RTm1ijakbmdcHyO6O45 ZJCAmRoysqKeoJ7VNd02S9qRJ/r2IJr8ORs9TKVUdNabutkcSpyPseMz4jMDoZT+uaJM vEw8dbr9m8o/ZRU8z2ztt5z+LTzQJYQMIqveayuFP/5V7wq3x1B+ev97+h8QYBByH+7/ Wp/RGHpHrXsl/gaM+sjorwkjT+KARg7PDn9QrjEObsRAPsi1QElna5LvscOyyQaIjFcb l2sw== 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=wI/fgkpfkM5obyK74TmNHrNP580D/KMa6vQsaGeQQqI=; b=NH26SoN7ACUp8Yvt9VGBsAiMD+ykVmN5ta1wrPphDIQZRgmmXeMsdo0Jc0ZkfT/k9P ErHsfw3GyMM0Vog8MDnQTkS8TQNcAhdmIbF6onJUINV4DHEeLl4APl7jCmIR7/qgFRNm M2r+ZYitEsfh31+A3Q/lZ4e2N7LUxRdLNjpODkiFge5ur1zXq1kKAH3J+sH6GxtZGGTL wIJQ3XmuWETPztbi+AZ0kyT4V1dDBPGqmkmFRXpnM8KqyjXBZhrtdLm4iuYEbkTeb11k azZ3VKxS19AilT1xhCxwEswC/g+Qv772Fixp+2rNM+I+NF+6aTPuQRmWr3EVPzh/EH6o mU/Q== X-Gm-Message-State: AOAM531oriSkPrKj24o/5iC21fHcMjSrYElfw+yLW04uHYN8a/G6ZRh2 4rdRSVkpJwaLFpBM+9Xy3aVcEyPUl+imLDonLgs= X-Google-Smtp-Source: ABdhPJyd4hbJJoz7MVpLhKdwWjJihK/B4ZF3+j6Cor622CQQx0yj77wdP62FwExNlngLMIAOQIH5D86FJsQqRqcQx0k= X-Received: by 2002:a67:fd93:: with SMTP id k19mr1133364vsq.52.1600177482152; Tue, 15 Sep 2020 06:44:42 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 15 Sep 2020 09:44:30 -0400 Message-ID: To: Benas IML Cc: PHP internals Content-Type: multipart/alternative; boundary="00000000000066bfdd05af5a5a7f" Subject: Re: [PHP-DEV] Compiler Optimizations From: chasepeeler@gmail.com (Chase Peeler) --00000000000066bfdd05af5a5a7f Content-Type: text/plain; charset="UTF-8" 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 --00000000000066bfdd05af5a5a7f--