Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116049 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 12454 invoked from network); 17 Sep 2021 01:39:28 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 17 Sep 2021 01:39:28 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 914BC1804C0 for ; Thu, 16 Sep 2021 19:19:19 -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=-0.6 required=5.0 tests=BAYES_00,BODY_8BITS, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, 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-ot1-f53.google.com (mail-ot1-f53.google.com [209.85.210.53]) (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 ; Thu, 16 Sep 2021 19:19:19 -0700 (PDT) Received: by mail-ot1-f53.google.com with SMTP id q11-20020a9d4b0b000000b0051acbdb2869so10942870otf.2 for ; Thu, 16 Sep 2021 19:19:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=zM9owd8/8+QqKscS/nwv0slf1XXzQx43rHSgvb2jwck=; b=nat8cJtYoPLBS+LwY/P5ymBgec7g/IIFV98jNqol4YTZ/xkmqpZy+eMK90fLYZ+c/L yoW9usZfFbZipQnWKxFhAQRxTySWH6CK3glUpTAdEXwIOzVFkn75Sc5YZwI0WHg90apH Jqovu+YBaQJldVZzvqxljfIbRRVUo7mS5hBzhAqV0Nv6hv7MsOQKfV+CzyxRzLoyaT2n drhx/LazDH9mwpJcartd3IkQillsNn5tADyfG/wSspCxFAWl0fUkli5W3Os10YxLE8Vc VM+91J9kj420wM6kZbVOfkYwGSQ4iHcSEXXTJ9mkQ72lZBbtSSeHFep2rcokw/alKqGq 3wAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=zM9owd8/8+QqKscS/nwv0slf1XXzQx43rHSgvb2jwck=; b=MXHBZJWJISupX5DZpl7mPMyd83vZKHduYk/5n+QPBqG5vTKorkhr5TCY5dJ6Rmwx92 EAoZc30JMtZl+zOKL1aVWVGevWiWuu3nL5wJSGFvcEbPSlzDTYlyN5ZQfs1+fjZsYjiS 2TtDBi3TVDhUUc6fNEv8IVaO4T3NavsMIUfnIfBXQQ1g2Z2YVL9tp/1DVhNTueSkbmaw BGnJ40TFVmPk7XOu7iZfd3yGUL4NDFvXj83m3crL0kBQZKHCM36rH0V/kixROnqCQW0s msMQ7vaSpQ5nL/k3J/I6UgHHOFsoJqZf9nGWak+Sg+ErJuL9pYPGZjqIchwgDBkOFG/v XYuw== X-Gm-Message-State: AOAM533Tui8v9vaXHnkfKtoUZtPh+bJVa7BhoDNPTSHGxSuzp7Luo2Sf 8XObnXREMOTnAFm/xzA3cj8kGMobmgjgC5UdiOA= X-Google-Smtp-Source: ABdhPJwarHx6FsFBzctFBrWtaa/swGU8Nn5DIbVh2mc6suGa3uXStiqDIstFjuwO69LwdGVunT1Mvl+g7fUyFxHpXp0= X-Received: by 2002:a9d:720d:: with SMTP id u13mr7538155otj.14.1631845155104; Thu, 16 Sep 2021 19:19:15 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 17 Sep 2021 04:19:03 +0200 Message-ID: To: tyson andre Cc: PHP Internals List Content-Type: multipart/alternative; boundary="000000000000cc6d8f05cc278ea0" Subject: Re: [PHP-DEV] RFC: Add `final class Vector` to PHP From: ocramius@gmail.com (Marco Pivetta) --000000000000cc6d8f05cc278ea0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hey Tyson, Would it perhaps make sense to drag in php-ds, which has matured quite a bit over the years? I'm referring to: https://www.php.net/manual/en/class.ds-sequence.php Is what you are suggesting with `Vector` different from it? Note: For some reason, I can't quote your post and then reply, so it will be a top-post =F0=9F=A4=B7=E2=80=8D=E2=99=80=EF=B8=8F On Fri, 17 Sep 2021, 04:10 tyson andre, wrote: > Hi internals, > > I've created a new RFC https://wiki.php.net/rfc/vector proposing to add > `final class Vector` to PHP. > > PHP's native `array` type is rare among programming language in that it i= s > used as an associative map of values, but also needs to support lists of > values. > In order to support both use cases while also providing a consistent > internal array HashTable API to the PHP's internals and PECLs, additional > memory is needed to track keys ( > https://www.npopov.com/2014/12/22/PHPs-new-hashtable-implementation.html > - around twice as much as is needed to just store the values due to needi= ng > space both for the string pointer and int key in a Bucket, for > non-reference counted values)). > Additionally, creating non-constant arrays will allocate space for at > least 8 elements to make the initial resizing more efficient, potentially > wasting memory. > > It would be useful to have an efficient variable-length container in the > standard library for the following reasons: > > 1. To save memory in applications or libraries that may need to store man= y > lists of values and/or run as a CLI or embedded process for long periods = of > time > (in modules identified as using the most memory or potentially > exceeding memory limits in the worst case) > (both in userland and in native code written in php-src/PECLs) > 2. To provide a better alternative to `ArrayObject` and `SplFixedArray` > for use cases > where objects are easier to use than arrays - e.g. variable sized > collections (For lists of values) that can be passed by value to be read > and modified. > 3. To give users the option of stronger runtime guarantees that property, > parameter, or return values really contain a list of values without gaps, > that array modifications don't introduce gaps or unexpected indexes, etc. > > Thoughts on Vector? > > P.S. The functionality in this proposal can be tested/tried out at > https://pecl.php.net/teds (under the class name `\Teds\Vector` instead of > `\Vector`). > (That is a PECL I created earlier this year for future versions of > iterable proposals, common data structures such as Vector/Deque, and less > commonly used data structures that may be of use in future work on > implementing other data structures) > > Thanks, > Tyson --000000000000cc6d8f05cc278ea0--