Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:100454 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 78764 invoked from network); 7 Sep 2017 19:14:05 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Sep 2017 19:14:05 -0000 Authentication-Results: pb1.pair.com smtp.mail=php@golemon.com; spf=softfail; sender-id=softfail Authentication-Results: pb1.pair.com header.from=php@golemon.com; sender-id=softfail Received-SPF: softfail (pb1.pair.com: domain golemon.com does not designate 209.85.220.193 as permitted sender) X-PHP-List-Original-Sender: php@golemon.com X-Host-Fingerprint: 209.85.220.193 mail-qk0-f193.google.com Received: from [209.85.220.193] ([209.85.220.193:33390] helo=mail-qk0-f193.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AC/26-10715-B7A91B95 for ; Thu, 07 Sep 2017 15:14:04 -0400 Received: by mail-qk0-f193.google.com with SMTP id g128so362308qke.0 for ; Thu, 07 Sep 2017 12:14:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=golemon-com.20150623.gappssmtp.com; s=20150623; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=QbqoNPtK2l++3QlPBORX+xWsog5/jx29ifkd8rltUQc=; b=vqPQn/NfSzemcrq0g6NUxCX76MByYnBKamwVVPV1vP1KAnqkbYut0dlNz1XrIgaOEC xRMnUCpedOxRrQmLKGuAWXog75RfCp9b/hYXalEXiRnC3a/XRmQEVcRhJ3/Mp+QYGrhv w8NqJNBL0gq5E0xJ2prrEFNRO7C8pzW5XpNNPlZIyqIj9rqXzVysgTMIAKtGS6M6WZGC V7x/Tq7/M5634El8uBIEFRWULWiObTkeAKJajzzV4cLPpHeuDaSPjIsde53OghfZ6ay/ W+t/9IP0Rdq1bxZtFRQq+CrtRBTE2yoSCgRJrIqvnqnw6k9G/8fMekTtnb48uCWmxw6E Kz9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=QbqoNPtK2l++3QlPBORX+xWsog5/jx29ifkd8rltUQc=; b=ozXn8uAPEW4JoBrtFCXkDbJ6pgimh2J1C63ZDl2301D7DwOuNinfqPT37TRjb6yIGY VTG492b48MYgMo+3sCyR6e8F1uNrhgzT0cUiKi90Hmq1fQY5daNmOey3Mh8oxrrQw7U2 BjeE4xFbvdVuBbGJ6jvkrc5E+uROGoDwyALwyA3mUFJFqdpwRkukXgm2BUntYh3R3mkg tMxrmnlpwT1xfXBnUzG2f0hRCeChWLt4ik5eYDCIldNmS3E6fCHvrd+rVPwVzqXTuVdS ohtudXw1KIRuWbx9x2JWnKNBpjjOl+af/hsD2T2+RjHfkTtiLcqa1OM+CdtdHX8zG/dt Hx3g== X-Gm-Message-State: AHPjjUgUnuXtTBiV2FgcbG2F8pFEZyTRcfEpiRoRxS6FDfGBPWFrooBX lmnEraJD5HPEKj8B2/k5LhyjdkepPH5K X-Google-Smtp-Source: AOwi7QAVnaC/Fij4R9eysx7KLRw5VyeNrS/zGw2f5absO1v1SdE84mKkduEwnJfWo67A7IGXq8B67XwY1PWoscjly3o= X-Received: by 10.55.7.22 with SMTP id 22mr493434qkh.43.1504811639911; Thu, 07 Sep 2017 12:13:59 -0700 (PDT) MIME-Version: 1.0 Sender: php@golemon.com Received: by 10.12.132.3 with HTTP; Thu, 7 Sep 2017 12:13:59 -0700 (PDT) X-Originating-IP: [206.252.215.26] In-Reply-To: References: Date: Thu, 7 Sep 2017 15:13:59 -0400 X-Google-Sender-Auth: uZ0tp8TCN_oJYVs-Ygp8GTIT15k Message-ID: To: David Rodrigues Cc: PHP Internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] array_filter vs for/foreach usage cost From: pollita@php.net (Sara Golemon) On Thu, Sep 7, 2017 at 2:13 PM, David Rodrigues wrote: > I understand that array_filter() should costs more than for/foreach because > it is a function call that call another function for each item, while the > for/foreach is a language constructor that works on a way totally different > and its optimized for this kind of job. > What you're describing is called inlining. At the moment, the main barrier to inlining is the symbol scopes. 1. Any variables used within the closure must not collide with the calling scope unless: 1.a: The value is captured by ref, or 1.b: The value has been captured by val and is reset between invocations. 2. Variables within the closure must destruct at the end of each invocation (loop). If you're seriously interested, I'd recommend prototyping an optimizing using the zend_ast_process hook. -Sara