rfc:closure_apply
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
rfc:closure_apply [2014/08/03 14:59] – linked ajf | rfc:closure_apply [2014/08/17 19:31] – Opened vote ajf | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== PHP RFC: Closure:: | ====== PHP RFC: Closure:: | ||
- | * Version: 0.2 | + | * Version: 0.2.1 |
- | * Date: 2014-07-29 | + | * Date: 2014-07-29, put to internals |
* Author: Andrea Faulds, ajf@ajf.me | * Author: Andrea Faulds, ajf@ajf.me | ||
- | * Status: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
===== Introduction ===== | ===== Introduction ===== | ||
- | PHP has had Closures since 5.3, and since 5.4 has had '' | + | PHP has had Closures since 5.3, and since 5.4 has had '' |
===== Proposal ===== | ===== Proposal ===== | ||
Line 41: | Line 41: | ||
My [[rfc: | My [[rfc: | ||
+ | |||
+ | '' | ||
+ | |||
+ | ===== Performance ===== | ||
+ | |||
+ | While not the sole benefit of this RFC, it can provide a performance improvement in some applications. | ||
+ | |||
+ | We use two test scripts, '' | ||
+ | |||
+ | <file php a.php> | ||
+ | $a = function () { | ||
+ | return $this-> | ||
+ | }; | ||
+ | class FooBar { | ||
+ | private $x = 3; | ||
+ | } | ||
+ | $foobar = new FooBar; | ||
+ | for ($i = 0; $i < 100000; $i++) { | ||
+ | $x = $a-> | ||
+ | $x(); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | <file php b.php> | ||
+ | $a = function () { | ||
+ | return $this-> | ||
+ | }; | ||
+ | $a = $a-> | ||
+ | class FooBar { | ||
+ | private $x = 3; | ||
+ | } | ||
+ | $foobar = new FooBar; | ||
+ | for ($i = 0; $i < 100000; $i++) { | ||
+ | $a-> | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | When run for 100000 iterations, '' | ||
+ | |||
+ | < | ||
+ | andreas-air: | ||
+ | |||
+ | real 0m0.259s | ||
+ | user 0m0.208s | ||
+ | sys 0m0.012s | ||
+ | |||
+ | andreas-air: | ||
+ | |||
+ | real 0m0.100s | ||
+ | user 0m0.094s | ||
+ | sys 0m0.005s | ||
+ | </ | ||
+ | |||
+ | If we up the iterations by 10x, the result is the same: | ||
+ | |||
+ | < | ||
+ | andreas-air: | ||
+ | |||
+ | real 0m1.966s | ||
+ | user 0m1.959s | ||
+ | sys 0m0.005s | ||
+ | |||
+ | andreas-air: | ||
+ | |||
+ | real 0m0.962s | ||
+ | user 0m0.897s | ||
+ | sys 0m0.015s | ||
+ | </ | ||
===== Backward Incompatible Changes and RFC Impact ===== | ===== Backward Incompatible Changes and RFC Impact ===== | ||
Line 54: | Line 122: | ||
Partial application (where a new closure is returned that pre-fills the first X arguments) is a possibly worthwhile (though more difficult to implement) addition. | Partial application (where a new closure is returned that pre-fills the first X arguments) is a possibly worthwhile (though more difficult to implement) addition. | ||
- | ===== Proposed Voting Choices | + | ===== Vote ===== |
This is not a language change, so a straight 50%+1 Yes/No vote can be held. | This is not a language change, so a straight 50%+1 Yes/No vote can be held. | ||
+ | |||
+ | Voting started 2014-08-17 and ends 2014-08-24. | ||
+ | |||
+ | <doodle title=" | ||
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
===== Patches and Tests ===== | ===== Patches and Tests ===== | ||
A branch which implements this (with a test) based on the current master can be found here: https:// | A branch which implements this (with a test) based on the current master can be found here: https:// | ||
+ | |||
+ | There is a pull request for review purposes here: https:// | ||
===== References ===== | ===== References ===== | ||
- | * As aforementioned, my [[rfc: | + | * As previously mentioned, my [[rfc: |
===== Changelog ===== | ===== Changelog ===== | ||
+ | * v0.2.1 - Added performance section | ||
* v0.2 - '' | * v0.2 - '' | ||
* v0.1 - Initial version | * v0.1 - Initial version |
rfc/closure_apply.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1