Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108211 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 38374 invoked from network); 22 Jan 2020 00:28:21 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 22 Jan 2020 00:28:21 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9EDB01804DB for ; Tue, 21 Jan 2020 14:37:05 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 21 Jan 2020 14:37:05 -0800 (PST) Received: by mail-wr1-f48.google.com with SMTP id q6so5177543wro.9 for ; Tue, 21 Jan 2020 14:37:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=x5/GFWnFIN/OmR3nyPOOqXoqECb/rIccjqReKbJAExI=; b=uA8myH61CHea0JhBgxi5WoQVxDy5JBSNfWVtO9bGF+jmLQOtgVGirutbIkAatGOoYJ sDINKSDkj6hpYq6JhZmyKHiObbizkeNQn9NrEAgnL7/yOmwOjukk4B+9R82ZWigd91Z3 Mh/aC+GpA5lwRtrcsX5wTIhjPuDzkJ2I39wXM4Otk96n8t/rUBd/v3xw/cqrsG+2VqkL 4BXX8G3NQgU18GFFqwQR0KIo38VMH4Ieshv54gwDMzeZmDjRuavQEXC8mzNNE2dLVwCZ UKSA01b65dS8RaMP+b+7RUKf0ebuJ2/hNUjevLINF2d/OVsv0gGb9oudNnutvu7kIUec LLLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=x5/GFWnFIN/OmR3nyPOOqXoqECb/rIccjqReKbJAExI=; b=FATIaVv8z0c/A1siZ28SbWuGTg9TWJTyHF8ngiJwvxPL7gOnRfCGQzhBibwaVuHSTr 8cPTCtBkMRfAYNDxly0tZsuprgaaxfA4tH4uony5TXRXSB3h7k4fPGCeNvzDajxAYnWo vxA1af9clolBkyLDY631CV7MyfF5GP7Ck3bl83tcYTFDTHs3eQaL+GEZ7DMcU38M3lox /nbXmkmdh7QUGWFh9JYZXJp8GwaxuVeld2tyQDJOjAFekyYoXe1kUqOh5TemxzoTfKpp 0PozwNKQOpvSU7ecZUvfF/F0H30wR4HMTMsxh8pDhQyYJd6jxypNMk7gOBjbGAJmF+J4 K8Pg== X-Gm-Message-State: APjAAAVcyy85D//5TYkeTHwSd3Pkbyuw67gJPJ1pbxv9Ln45OC6Adf2e gL6hO1oFU43WpNGqrsXTaVQNZJQH X-Google-Smtp-Source: APXvYqyEtrBRon1vRE/2fY3K33JtysfUImKuPVcURoJB6QwxWFQihl/jGpXg6j8YrBPdFtNiUHK6LA== X-Received: by 2002:adf:fe43:: with SMTP id m3mr7643841wrs.213.1579646219776; Tue, 21 Jan 2020 14:36:59 -0800 (PST) Received: from [192.168.0.14] (cpc84253-brig22-2-0-cust114.3-3.cable.virginm.net. [81.108.141.115]) by smtp.googlemail.com with ESMTPSA id k16sm56502386wru.0.2020.01.21.14.36.58 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 21 Jan 2020 14:36:58 -0800 (PST) To: internals@lists.php.net References: <5DC86728-1BBF-4DCA-8A6B-9B0B190DB99D@newclarity.net> Message-ID: Date: Tue, 21 Jan 2020 22:36:57 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.3.1 MIME-Version: 1.0 In-Reply-To: <5DC86728-1BBF-4DCA-8A6B-9B0B190DB99D@newclarity.net> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB Subject: Re: [PHP-DEV] Typed array properties V2 From: rowan.collins@gmail.com (Rowan Tommins) On 20/01/2020 00:53, Mike Schinkel wrote: > One approach mentioned by Andrea Faulds was to extend the hashtable (ref: your article[1]) and count types as assigned just like we currently count references. So a 10,240 element array of ints could have an internal tracker showing that the array contains type(s): ['int' => 10240]. Append a string value to the array and then the types would be ['int' => 10240, 'string' => 1]. This would work really well for simple types like 'int' and 'string', but loses its advantage fast with things like interfaces and pseudo-types. For instance, if you have an array with objects of 20 different classes, and need to check it against a constraint of SomeInterface[], you still have to test all 20 classes to see if they implement that interface. The overhead is also rather high, because you have to allocate memory for this list on every array, and keep it up to date on every write, even if it's never used. I've had a similar idea in the past, but rather than trying to list the types in advance, just cache them after passing (or failing) a type check, so more like [ 'SomeInterface[]' => true, 'SomeOtherInterface[]' => false ]. Even if you just wiped the cache completely on every write, I think that would give a decent boost, because there will often be cases where a value is passed through a series of related functions all expecting the same type. The worst case pseudotype is probably "callable[]", because it's actually context-dependent (e.g. [$object, 'privateMethod] is only "callable" inside the same class as $object) so can't be pre-calculated or cached. That would be problematic even with full generics - logically, List would check each member was callable when it was added to the list, but it might turn out not to be callable when it was accessed later. Regards, -- Rowan Tommins (né Collins) [IMSoP]