Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111798 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 92419 invoked from network); 2 Sep 2020 22:49:28 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 2 Sep 2020 22:49:28 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id ED7761804D4 for ; Wed, 2 Sep 2020 14:54:26 -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, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) (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 ; Wed, 2 Sep 2020 14:54:25 -0700 (PDT) Received: by mail-pf1-f173.google.com with SMTP id o68so485813pfg.2 for ; Wed, 02 Sep 2020 14:54:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:references:from:to:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=44RKmJ56BHG0CAQ0rKU+aJkZK7vED3+/AFemrTwK74c=; b=Vp+gU6R8VVgZVV8xryU8BeTgoN0DXgj0wbYoUD9gHr4NIWZeuGoc0dia7Fun/KpMOy PDt3gLoXActGdUiM6oP9AhoucLsuWzvkv0dS+VqtiYoJttHNMcHPpwPM/pIxyh6na6zg xWg4hnCjX/4OFibTUwDFUzej4RcbcNLqq+/TaNuETs2hQPCKPkr07NJnGNSRgSl+bRd6 /FUj6hKZ6smCj58ePgxm6c/EGmv5BUkuYt5dQ+DoFF1fxRipKbkrMsddYClvw2bWDdGN C7R97/WvMpJPjtyh/6vPNuq/9sZVEHmAeLcVDBu7XqOmM/+WbwcucYdou5kN1AUGsNV/ bJBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:references:from:to:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=44RKmJ56BHG0CAQ0rKU+aJkZK7vED3+/AFemrTwK74c=; b=L8ckxKYFu6Tqslrk024CYNcEBJQy/Tq6UPXpsCZN4R7WYmTUOs8rz+gbj89DpgVPKl imz5vGjOqWXmH4SfpJG4EB3tEWj13XT/Sn9pw74sv1rDf0wfJhVtCiZIXdiu68M2+EV0 8Q3v1fDpTiKxgp+JUDlpECKSfVw3PuD42i9XEZpOokruGSMhUbuQTbVBUwtZ2vaY6TQh NSEgiKsoTljfEsAdqKYa6C1RihuCpIgoTlT/5bwzfW9RvwLvkwX46OqZTBleMEEDP8BR SnVZJYOGVxAN2MFgjlm0oKFKLv3ea9X/Ytm6GH7xVHtmb5I2RbxWO7VrAJwlqPAbWTMi UfhA== X-Gm-Message-State: AOAM530MDI5UJyaZW799J9c8IoKliJej+pCLJnUK52zcRG1DtyW9KRYM 52TwfosuUjb4uu1L4AK3EUFvtjSO2URy X-Google-Smtp-Source: ABdhPJzDztAXOE2yyW7nn3xtyMitl1ZoDWPS+O+6yxBnTh6vCp31CSgxEt3zg28jL28amD69PNi2JA== X-Received: by 2002:a17:902:ee0b:: with SMTP id z11mr418926plb.268.1599083663962; Wed, 02 Sep 2020 14:54:23 -0700 (PDT) Received: from Stas-Mac-3.local (ec2-34-209-88-149.us-west-2.compute.amazonaws.com. [34.209.88.149]) by smtp.gmail.com with ESMTPSA id h11sm515941pfq.101.2020.09.02.14.54.22 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 02 Sep 2020 14:54:22 -0700 (PDT) References: <89FF9360-609A-439F-BDBE-B3B4C141E00F@newclarity.net> To: PHP internals Message-ID: <95eddd89-9915-14fc-7649-9de0e8dd349d@gmail.com> Date: Wed, 2 Sep 2020 14:54:22 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 MIME-Version: 1.0 In-Reply-To: <89FF9360-609A-439F-BDBE-B3B4C141E00F@newclarity.net> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Draft RFC: foreach iteration of keys without values From: smalyshev@gmail.com (Stanislav Malyshev) Hi! >> In theory, this should be a general performance win any time one >> needs to iterate over only the keys of an iterable, because it does >> not require the use of an O(n) iteration and building of the array >> that array_keys() would, plus it works on non-array types (such as >> generators or iterators). It also is more performant than >> foreach($iterable as $key => $_) {}, because it omits the opcode >> that instructs the engine to retrieve the value. (Presumably, a >> future direction could include using this request to inform >> generators or To me, it looks like the case of premature micro-optimization. Unless there's a benchmark that proves it achieves speedup in a real-life application (not tight-loop synthetic benchmark) I think foreach($iterable as $key => $_) {} is completely fine. My opinion has been and remains, absent new data, that if your code performance hinges on a couple of simple opcodes being there, maybe you'd better implement that part in C, but in most real-life applications it is not and any performance gain you might get from such syntax is microscopic. -- Stas Malyshev smalyshev@gmail.com