Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116058 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 39380 invoked from network); 17 Sep 2021 05:03:55 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 17 Sep 2021 05:03:55 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D70831804DB for ; Thu, 16 Sep 2021 22:43:47 -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=-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_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-oo1-f46.google.com (mail-oo1-f46.google.com [209.85.161.46]) (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 22:43:47 -0700 (PDT) Received: by mail-oo1-f46.google.com with SMTP id v20-20020a4a2554000000b0028f8cc17378so2860101ooe.0 for ; Thu, 16 Sep 2021 22:43:47 -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=JGDTY9sEUfxdisUY1fN0+Pk41ahgmncmpyLmQUwui4M=; b=AgwaMRwWq/pIvp4QzTIlPCt3AcFULj5ekrt2kh6akmdWtPYJv8H7JOhsZWJeC6efBu e4CJsWg+85AM7cqrF6K1vcGyFbkS1MJYGFweKmTH7EpLH1cqj9eGFBB/xqhqIzRE2EwB pyn6eO5OA3UJmW+GUxwiuoxGrAJUFTkg6el2YxAcVc2No55y9Q522C/VF2zQTlJYu0nN jK1VRw7tEK7ycVsICcY4nAohR9FTxXDqpft57/QpKkayhRArXijE1Vk8slPPEWFEGMpG oeg4A2jlMNN/6gA4o6wD4ICZ665pNCFFNV0grp5iQ9bn+QCtfijMpktrutf/xVnagj6B bvMg== 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=JGDTY9sEUfxdisUY1fN0+Pk41ahgmncmpyLmQUwui4M=; b=OpE2XQgqkwK82muLa7gykvXOFnAjCy+D71zBJYdeyLAYXy8IeEyzRPCZrRarU2k685 ROyFE70GoDy7OsSlnyx/h8ljHcskUWiNlZUVIE/GnqvCjjEEsx0sUwbAOwlbqfxcFpeg s+RZLNYUPwFSi/guJSO6PauWLr51MkwUUTyC6VXzuSn7EK4j7jp82ctCVi/itGAevG/I bjozx0bK7PIBaAbMhIuS+QFgKzx4kgk2kTWkcoB+DHEghQ42bpQFDnAtWC+35xJkey3W k5ezi5Vq0qgbc/NG4KAvz29mAEABP4i6wafic3fltsES3zvj8451tU8aRwmqXIrTdC7e KuLQ== X-Gm-Message-State: AOAM531B/PQpsbfw9PjjBIu1Bi16Ep18ghDU8kr3qZdH8uYK5Ey+CZkl xw+xY8tukhqn88o06pMQg9TqYmR3UcgMm6obb60= X-Google-Smtp-Source: ABdhPJxOUqMR2yDEaNqX03aONwfm1eNy8HDpV2ejM1Tx7pgFAZTMSaB9RfXd/fMiDLyFocidK00Fg6TRyjMyk6DPpxU= X-Received: by 2002:a4a:d814:: with SMTP id f20mr7366064oov.51.1631857423456; Thu, 16 Sep 2021 22:43:43 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 17 Sep 2021 12:43:32 +0700 Message-ID: To: tyson andre Cc: "internals@lists.php.net" Content-Type: multipart/mixed; boundary="0000000000000d4e2905cc2a6af0" Subject: Re: [PHP-DEV] RFC: Add `final class Vector` to PHP From: pierre.php@gmail.com (Pierre Joye) --0000000000000d4e2905cc2a6af0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hello Tyson, Vector support would be very good. JIT can do a lot with them if we have a clean Vector implementation, or even without JIT. What is your base inspiration for Vector? I do like the pretty standard C++ Vector implementation: https://www.cplusplus.com/reference/vector/vector/ Where a Vector is initalizied with: $myIntVector =3D vector; What is key for performance is also the alloc/realloc/free strategy. In C++ (or most C or other languages custom) gives control to the creators to define max size, capacity, etc. If a non typed Vector is the goal, then I am less in need of it, still good to have but not as good as a clear pure Vector support :). Also I think it will be very good to have more details about what this RFC proposes in the RFC. It is kind of hard to follow right now, with all external links. RFCs are better if they act as a real specification :) Best, Pierre On Fri, Sep 17, 2021 at 9:10 AM tyson andre wro= te: > > 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 inte= rnal array HashTable API to the PHP's internals and PECLs, additional memor= y is needed to track keys (https://www.npopov.com/2014/12/22/PHPs-new-hasht= able-implementation.html - around twice as much as is needed to just store = the values due to needing 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 lea= st 8 elements to make the initial resizing more efficient, potentially wast= ing 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 exceedi= ng 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` f= or use cases > where objects are easier to use than arrays - e.g. variable sized coll= ections (For lists of values) that can be passed by value to be read and mo= dified. > 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 `\Vecto= r`). > (That is a PECL I created earlier this year for future versions of iterab= le proposals, common data structures such as Vector/Deque, and less commonl= y used data structures that may be of use in future work on implementing ot= her data structures) > > Thanks, > Tyson > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > --=20 Pierre @pierrejoye | http://www.libgd.org --0000000000000d4e2905cc2a6af0--