Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114812 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 91081 invoked from network); 10 Jun 2021 14:00:56 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 10 Jun 2021 14:00:56 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 80384180539 for ; Thu, 10 Jun 2021 07:16:13 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam08olkn2073.outbound.protection.outlook.com [40.92.46.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 10 Jun 2021 07:16:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UHbDnjJSXX3VTlvY6XodoEfuZSUUlsyUSKNCRF60lGwVfEuR3+A53tcafdUz5d9A6iTLjJ59q8sywXv8SCF4B3MXSZwg7ytG6M6vc4+HhJbmk3olFm10bgssvectf8R4BgjTwTR9hazZK6e4li1Fi2d9HuQSkJ+8Pn+NXNxKSzSJ7215cxuYp4zpscT5xU+loVVR1/nZ+qOYY6wi9kg9I86IGtSO3Zflq2JS2SBF4V51+PsbqAS9fpz50TIqYgNMuhpvIiwIexWXSntcK1BewkpbZl8aUAqQeOj/04UPAHGHmsPAFXWJ0eeSL3tW0bVmNHTmxeB3nwHfxQNSxo3Kiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=trBHNcPsAaGEHBtj/MXFfZJK5uMabp86WBokRDVC6ik=; b=USG/L/8vv5mOzQ4lqECpyzUrJM3/r1YkrZlmZZKcRzD/7R8PmihPachzK/n8l581k0WnvjthqvGpRPWd5lbKkGViVc7c8Tf3qjT3WHTHddbCSLLAS64Wg+Udco+Y96G+y2wHZDDQw+pgPVA7XgWWZY5GACKecrcK7k8k2jRnGbWZpg33tEHq9Zw5oEQqHqBwcjc1lot8xnWkmlgx5rFZrs5N3i3eCtDFa/DIvND83+V1I5kAOLrH7sxtv77VTw/fbW7138I8TF8PUXiC3opMTjcdewpt2LkwcRGiNMFfJvde14b8FmMkmCjlsZOaDJc1gNtByUb+lQmnOPw48qlYiw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=trBHNcPsAaGEHBtj/MXFfZJK5uMabp86WBokRDVC6ik=; b=YAEL5YiSzVvthfkj4EZc5pN6fkGlrr+DFvUDXGORIrrfaSMr6Zu1qCR1wWobnvTkUHVEE+MzQCnZrupt/RxsmfwIKMuRq204miKWszjXxL+KO5lSzjP990i7xNBwOQwAp9Bv1kg8z3/D8pJbaus7SR8vQ/ZNF/SC5ZjT8sSxdpfW4+9WWntk0XEYPZS/fQuFQdDMDUV4iOgY9nD+wJRaM1ivc412YYq18ypdcmmaM6ph+BPoR8P8RCKMrbutQHasT5mjjXsmNsgFDqte8ORM2ZL9od9GvC/0SYlwacQvRgw8dZFwiodN7qTwDk0hXi70mcRBGWNzUkdX/M2w2jOCRQ== Received: from DM6NAM04FT036.eop-NAM04.prod.protection.outlook.com (2a01:111:e400:7ea3::46) by DM6NAM04HT141.eop-NAM04.prod.protection.outlook.com (2a01:111:e400:7ea3::236) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.18; Thu, 10 Jun 2021 14:16:11 +0000 Received: from DM6PR07MB6618.namprd07.prod.outlook.com (2a01:111:e400:7ea3::40) by DM6NAM04FT036.mail.protection.outlook.com (2a01:111:e400:7ea3::293) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.18 via Frontend Transport; Thu, 10 Jun 2021 14:16:11 +0000 Received: from DM6PR07MB6618.namprd07.prod.outlook.com ([fe80::20ed:6cd1:4fe2:eea7]) by DM6PR07MB6618.namprd07.prod.outlook.com ([fe80::20ed:6cd1:4fe2:eea7%3]) with mapi id 15.20.4219.023; Thu, 10 Jun 2021 14:16:11 +0000 To: "internals@lists.php.net" Thread-Topic: [PHP-DEV] Re: RFC: CachedIterable (rewindable, allows any key&repeating keys) Thread-Index: AQHXACLkMdQqZoaVtUy2vSZWXRDmOasLeFTVgAHzyACAAJB9eg== Date: Thu, 10 Jun 2021 14:16:11 +0000 Message-ID: References: , In-Reply-To: Accept-Language: en-CA, en-US Content-Language: en-CA X-MS-Has-Attach: X-MS-TNEF-Correlator: x-incomingtopheadermarker: OriginalChecksum:D84B5BCEDF9F73B756EE38ED1E69D4BB5F83A5664A8F5BBD501DC2369E1BB8BF;UpperCasedChecksum:045C3ABD2A9BA0081991323F5EDAF66A2F963CD688137AB8695E53532E42D426;SizeAsReceived:7117;Count:44 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [KDdVKABL+cRfMaSgcPAIEi8Bu0pxHHs4] x-ms-publictraffictype: Email x-incomingheadercount: 44 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: def77142-e685-47be-ad35-08d92c1a4c83 x-ms-traffictypediagnostic: DM6NAM04HT141: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: JA7adL4+gMd0YE3EZWlU3AFMhrNLt2UP8AbL2LdTcMTfb1gp4YWw0dNoX/KLDuTuOW1ROr+dOqUhw8YAcWFnwvCxYSWeoh/QG/2p6wP0miyP0zByt/t57viFR3iIdNIP86SCS5HBcXF10TfeqAXmY7uuGBNbLdyMp9KZgowqIHFeKcuZBGJdLKP+cJLjk2xbkRHcdDhfVlhvu5B/GvTlaw72rO3Ub8Zl+cL1uJpCGQ/AsJmvJqySuH7Qi4fQn2KWg9nWfzsi5ETfJsJ0nabV5xs5hV5tUV1eXymum6HFTsWcKKop3oR9KEaFyUSQXul+0EtdtVMkM2Y4d0VWJ9Y0E97MzPUkaOISiRJH860sUmQRZLxjG1mKHusOQHqLgVj1TxzEpGCNz+SSNJZaUWSL0aZrR35CkTIg6UWl9Fm8hdLzLfxTn/oOZWAc64OPwtcmOZgYYQXjKUyCst/CxHj4+w== x-ms-exchange-antispam-messagedata: 62yGrhv9tqGmDtLHu2xhv00x8Qnr/sukZxdjs8E2pENU4YOFabSdSEWILeMgsS26Zx7O6aX6FrbBewCUQTGw8Kgmbyk0M7SpUA9XILJSr6jEL4OrVpv4Z6Cltft6RolxjpfQ3JAI403nzO/LWoqcWA== x-ms-exchange-transport-forked: True Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: hotmail.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-AuthSource: DM6NAM04FT036.eop-NAM04.prod.protection.outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: def77142-e685-47be-ad35-08d92c1a4c83 X-MS-Exchange-CrossTenant-originalarrivaltime: 10 Jun 2021 14:16:11.3336 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6NAM04HT141 Subject: Re: [PHP-DEV] Re: RFC: CachedIterable (rewindable, allows any key&repeating keys) From: tysonandre775@hotmail.com (tyson andre) Hi Alex,=0A= =0A= > > I've created a new RFC https://wiki.php.net/rfc/cachediterable adding C= achedIterable,=0A= > > which eagerly evaluates any iterable and contains an immutable copy of = the keys and values of the iterable it was constructed from=0A= > >=0A= > > A heads up - I will probably start voting on https://wiki.php.net/rfc/c= achediterable this weekend after https://wiki.php.net/rfc/cachediterable_st= raw_poll is finished.=0A= > >=0A= > > Any other feedback on CachedIterable?=0A= > =0A= > Thanks for explaining 4 months=A0ago about=A0my=A0concern.=0A= > I think I understand the main real impact of an eager iterable cache vs a= lazy iterable cache from a functional point of view:=0A= > - exceptions=A0are thrown during construction vs during the first iterati= on=0A= > - predictable=A0performance also=A0on the first iteration.=0A= > =0A= > How did you gather the information that eager implementation is more valu= able than lazy one? I'm mostly curious also how to assess this as technical= ly to me it also looks the other way around. Maybe mention that in the RFC.= =0A= > I was even thinking=A0that CachedIterable should be lazy and an EagerCach= edIterable would be built upon that with more methods. Or have it in the sa= me class with a constructor parameter.=0A= =0A= One of the reasons was size/efficiency. Adding the functionality to support= lazy evaluation would require extra properties to track internal state and= extra checks at runtime, =0A= point to the original iterable and the functions being applied to that iter= able - so an application that creates lots of small/empty cached iterables = would have a higher memory usage.=0A= =0A= Having a data structure that tries to do everything would do other things p= oorly =0A= (potentially not support serialization, use more memory than necessary,=0A= have unintuitive behaviors when attempting to var_export/var_dump it, =0A= surprisingly throw when being iterated over, etc)=0A= =0A= > Also, being able to have a perfect userland implementation, not very comp= lex, even considering the lower performance, is not that good for positive = voting from what I remember from history...=0A= =0A= 1. The userland polyfill included in the RFC is an incomplete implementatio= n that only supports iteration. =0A= It's meant to be as fast as possible at the cost of memory usage.=0A= It's not even an IteratorAggregate, doesn't support json encode, createF= romPairs, and many other functions.=0A= 2. Virtually all of the spl iterables that don't deal with filesystems can = be reimplemented in userland.=0A= (https://en.wikipedia.org/wiki/Turing_completeness)=0A= =0A= Even complicated extensions such as redis or memcached can be reimplemen= ted in userland on top of sockets,=0A= but with higher cpu usage than native extensions (https://github.com/pre= dis/predis/blob/main/FAQ.md#predis-is-a-pure-php-implementation-it-can-not-= be-fast-enough)=0A= =0A= The benefit of having data structures internally is the fact that develo= pers who learn them can use them in any project without adding dependencies= =0A= (even in single file scripts) and that applications using CachedIterable= would have much better performance =0A= =0A= Also, you and Levi have pointed out that iterable/iterator functionality is= traditionally on-demand=0A= (https://en.wikipedia.org/wiki/Lazy_evaluation) (e.g. iterables such as Cal= lbackFilterIterator, RecursiveArrayIterator, etc)=0A= =0A= As a result, I'm thinking CachedIterable is really not a good name for the = eagerly evaluated data structure I'm proposing here,=0A= and that there was confusion about how the data structure behaved when the = name CachedIterable was suggested.=0A= If functionality like that described in https://externals.io/message/114805= #114792 was added, it could use the name CachedIterable instead.=0A= =0A= So I'm probably changing this to `ImmutableTraversable` as a short name for= the functionality,=0A= to make it clear arguments are eagerly evaluated when it is created.=0A= (ImmutableSequence may be expected to only contain values, and would be con= fused with the ds PECL's https://www.php.net/manual/en/class.ds-sequence.ph= p)=0A= =0A= Thanks,=0A= Tyson=0A=