Re: array_filter vs for/foreach usage cost

From: Date: Thu, 07 Sep 2017 19:13:59 +0000
Subject: Re: array_filter vs for/foreach usage cost
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-100454@lists.php.net to get a copy of this message
On Thu, Sep 7, 2017 at 2:13 PM, David Rodrigues <david.proweb@gmail.com> 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

« previous php.internals (#100454) next »