Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111800 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 20629 invoked from network); 3 Sep 2020 05:01:34 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Sep 2020 05:01:34 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B91A81804D4 for ; Wed, 2 Sep 2020 21:06:36 -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.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-qt1-f180.google.com (mail-qt1-f180.google.com [209.85.160.180]) (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 21:06:36 -0700 (PDT) Received: by mail-qt1-f180.google.com with SMTP id t20so958252qtr.8 for ; Wed, 02 Sep 2020 21:06:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=cYQNREQ31ynklvuQq/L5hl6t2qtP5dCfAYxVzqPep0Q=; b=RsVs1RwN8ZPv6vtuoOXRJQXIvzWVfZjejdbi1OX+kyNAdhnTLivKHog3ptU7C8svTy B7gDMXDHzekxn/snDqK/eQEiauU89zfSKqaPo5zlFZ/4mWk9VwrEkIrBAq8uTAohJ4Mu UVozbK9I2luz5uDiDHeRLpsMe+XIcPTOkJdtZn375aJiUhfWWMExWQsJDJqYM4J2dm/+ x28lF2cVe62WIvhkGv7OER4J6rx44BQR4jHOnQ1L4DIwVNnFarYG8nCak2JLl1/vDdPo vRC43iBTb6F7oSBxvJxmXx3B/GPRikF/DXmquiTyhpxdC3DkWviHNa5m+F0ChAIiqv7s ofJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=cYQNREQ31ynklvuQq/L5hl6t2qtP5dCfAYxVzqPep0Q=; b=oRZlxaVr2AtE7/XEFoaVoVfQH/Wy3bYXOQKLnLrMx6omsdu3A3YoH2CUANZTzjUivq mHPDsaW/tPkzf6VskPD3cnW6UHpmGuwnlTRRIEeo5FV5SWupXEgm81DoBY2M3TnWHANL J7NAfnxp3ktTnXCg09lQeqCPDWcv9JMVSgC0NtM0sok3+znewHcuTJrAKdVvBFlJrDN4 iANQtIjR4UYp0jsorfGU+oqBaI0HgkWB+R7rZTv5GkH2JvI8je4lsN7WtkiHUW23VVEd YBCU5GL1W+7KrGWLJAMb//pX4l22j3YOrkqlldTNyaZ99i+v/RTydgFtzXCJs54O6lq4 w82Q== X-Gm-Message-State: AOAM532aCok2t5w40hOE0kx00dJZozvYuCNhMK7YVAScV33p16xfI4xq OPFybekKA01yPA8imW5Myf2CyQ== X-Google-Smtp-Source: ABdhPJxNmth3SVRow7URaT4zTc7Gsqgw6Z1PKSvG3xKhOisaykdJ0Ts7+CqEgwucolVlN9HP5U+bDw== X-Received: by 2002:ac8:4f4e:: with SMTP id i14mr1480162qtw.213.1599105994031; Wed, 02 Sep 2020 21:06:34 -0700 (PDT) Received: from ?IPv6:2601:c0:c680:5cc0:8809:ec13:5bce:3bd8? ([2601:c0:c680:5cc0:8809:ec13:5bce:3bd8]) by smtp.gmail.com with ESMTPSA id n203sm1316560qke.66.2020.09.02.21.06.32 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Sep 2020 21:06:32 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.1\)) In-Reply-To: <95eddd89-9915-14fc-7649-9de0e8dd349d@gmail.com> Date: Thu, 3 Sep 2020 00:06:32 -0400 Cc: PHP internals Content-Transfer-Encoding: quoted-printable Message-ID: References: <89FF9360-609A-439F-BDBE-B3B4C141E00F@newclarity.net> <95eddd89-9915-14fc-7649-9de0e8dd349d@gmail.com> To: Stanislav Malyshev X-Mailer: Apple Mail (2.3608.120.23.2.1) Subject: Re: [PHP-DEV] Draft RFC: foreach iteration of keys without values From: mike@newclarity.net (Mike Schinkel) > On Sep 2, 2020, at 5:54 PM, Stanislav Malyshev = wrote: >=20 > Hi! >=20 >>> 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 =3D> $_) {}, 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 >=20 > 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 =3D> $_) {} 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. If it adds a micro-optimization, great, but allowing a developer to = explicitly signal intent is the primary argument for adding void. IMO. -Mike