Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107658 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 88418 invoked from network); 24 Oct 2019 16:15:15 -0000 Received: from unknown (HELO localhost.localdomain) (76.75.200.58) by pb1.pair.com with SMTP; 24 Oct 2019 16:15:15 -0000 To: internals@lists.php.net References: Date: Thu, 24 Oct 2019 15:01:39 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit X-Posted-By: 94.8.59.3 Subject: Re: [PHP-DEV] Re: [RFC] Union Types v2 From: marandall@php.net (Mark Randall) Message-ID: 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