Re: Re: [RFC] Union Types v2

From: Date: Thu, 24 Oct 2019 14:01:39 +0000
Subject: Re: Re: [RFC] Union Types v2
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-107658@lists.php.net to get a copy of this message
On 24/10/2019 13:47, Rowan Tommins wrote:
The simpler idea I had in this area was caching what type checks a value had passed, either on each zval or perhaps just at the class level, so that checking the same type again would be much faster, even if it was a complex union with multiple interfaces.
Last night I was playing about with caching the last passed interface as part of the instanceof_function. https://gist.github.com/marandall/38d7dba6600889d897f2c8fc57532f31 When used in the likes of loops which are performing the same check over and over, it yields about a 18% increase when using a 3 layer deep nested interface. It currently just stores a cache of the last match in the class entry so it would hit as many uses as possible. For T_INSTANCEOF it could potentially use an extended cache slot to store a reference to it (would need expanding out into a separate struct as the cache slot is already used for converting the static name to a ce). I'm less clear about how we could handle it for everything else, like parameter type validation. The underlying implementation already seems pretty well optimized so I'm not sure where a performance penalty is to be found. -- Mark Randall

« previous php.internals (#107658) next »