Morning, > This wouldn't affect the performance of untyped properties at all.
There are extra instructions in that code. When the code you have is only 5 instructions, adding 1 more instruction makes a 20% increase in instructions ... That is what we are looking at in these micro benchmarks; The number of instructions is so small, that even the small difference is measurable. Of course you can measure the difference, and obviously there are going to be more instructions, but we should only care about what effects real world code. This doesn't effect real world code. Cheers Joe On Sun, Jun 12, 2016 at 2:03 PM, Rasmus Schultz <ras...@mindplay.dk> wrote: > Pretend I know (basically) nothing about how PHP was implemented, because > I don't ;-) > > But I don't understand why regular property updates should be affected by > this at all? > > If I had to implement type-checked properties in plain PHP, I would do > something like this... > > /** > * @property int $price > */ > class Product > { > private $_price; > > public function __set($name, $value) { > if ($name === "price") { > if (!is_int($value)) { > throw new UnexpectedValueException("..."); > } > $this->_price = $price; > return; > } > throw new RuntimeException("undefined property {$name}"); > } > > public function __get($name) { > return $this->{"_{$name}"}; > } > } > > I would have guessed an implementation of type-checked properties would > work in much the same way. > > Of course, it wouldn't use "_" as a prefix for the underlying property, > but some other magic byte, much like how private properties are internally > prefixed with a magic byte, right? > > This wouldn't affect the performance of untyped properties at all. > > Of course typed property writes would be more expensive, but that's to be > expected. > > > On Sat, Jun 11, 2016 at 3:45 AM, Yasuo Ohgaki <yohg...@ohgaki.net> wrote: > >> Hi Dmitry, >> >> On Fri, Jun 10, 2016 at 9:37 PM, Dmitry Stogov <dmi...@zend.com> wrote: >> > I hardly worked on implementation of this patch for a week, but I still >> don't like it. >> > >> > It makes 15% slowdown on each property update in existing PHP code >> (without types), and I don't see a way to improve this. >> > >> > Update of typed properties is going to be even more expensive. >> > >> > Benchmark results are included into RFC (and not changed with the >> latest version of the patch). >> > >> > >> > -1. >> >> If we are concerned about performance, DbC would be the only solution >> for this kind of problem. i.e. Validate fully during development, do >> minimum validation on production. DbC helps type inference also. There >> may not be enough time for discussion, but do you think there is >> enough time for implementation? I suppose implementation is >> straightforward, so it might be OK to have RFC w/o implementation. We >> have 2 options anyway. It's waste of time for having 2 >> implementations. Would you like to proceed the RFC for 7.1? >> >> Regards, >> >> -- >> Yasuo Ohgaki >> yohg...@ohgaki.net >> >> -- >> PHP Internals - PHP Runtime Development Mailing List >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> >