Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116082 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 44491 invoked from network); 18 Sep 2021 01:51:08 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 18 Sep 2021 01:51:08 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 867F21804B2 for ; Fri, 17 Sep 2021 19:31: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=-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-oi1-f173.google.com (mail-oi1-f173.google.com [209.85.167.173]) (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 ; Fri, 17 Sep 2021 19:31:12 -0700 (PDT) Received: by mail-oi1-f173.google.com with SMTP id p2so16652428oif.1 for ; Fri, 17 Sep 2021 19:31:12 -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=y42g/DEQ3duJxpJiriQ9vvK1+8nu4JPWE5qp1AImyvs=; b=aSDZd64j66oRUNb395CqoCDP+06f9y92tFvrL/KsmgYc3GwwLa/k3KB+Jxo76Mwc0D p4rzlHWn2pnIn2YOZkpmJeTyw04+ic6bjs3OaRsRyR15lYdm7SPd5RypO62hPUDEEfK0 U087dvQzUPwYkxKwHGoVpSrIx+I+PPgC56qcnZqKQCtPNx/u71hDOTqPz8FR2+cHF34w 9RUNuQHIneK9Ca+3L6gWhpbcOtoVnCEpEy0Pm45+jsT9ZBY3KSjdQ0yG+mFqxw+hQc6B 4+QgSTA8PA4t73rwSBjbfbdqSUSVbUzTavt46O9cG1kHERF4+dYcxDcV2o0SHvzsblFk nXGQ== 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=y42g/DEQ3duJxpJiriQ9vvK1+8nu4JPWE5qp1AImyvs=; b=rSmXa8WdAkUOENr5lTZPMCSVBqNCZdKrUm2JlQHS/Lzs+VGJ4DRMB2mNzKH1DJfYxu KcB0RAQAb47aj6AMTFhHedcGasmSpRnOgKWuDlt1UOh6GTXrLy98kjHDv96FTp3SL2vs O5ou8BkUpdxQTdBIGmQ2XFKK8O63ySgSEY8SgdpL7gp0kQL+Qs0b9tYxOl6/fC4p20ae C+e1IPljprbdAVqEjy8bBcJoFad8AAsBiagB9xaYsllTThBQslby0CWskcsOAGTVqliI 5WXVDW8zusWcOI+VslEbeONuX82DQ3Pz/w0WHYZrO01Mfxgc7gfhlf+g81To0GGX5IVn fo4w== X-Gm-Message-State: AOAM533uU6m8RACM0Cu5BrLKcuBNk1Ecgqr3qL3x4i3DoUaakBtXCyqb SUAaCnUskQkHaj2NocmMUmhFuhyzc+hGyXfwXH3bdFvl0xc= X-Google-Smtp-Source: ABdhPJwFqF61Txfau0mj0JQzI+Ndi9ZsxP8I4Jo9WNY5pgT/w508O8TTZ73UTq0vinQxHjxHfvtedH+t1r/FP8uF5AQ= X-Received: by 2002:a05:6808:281:: with SMTP id z1mr6335641oic.30.1631932269200; Fri, 17 Sep 2021 19:31:09 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sat, 18 Sep 2021 09:30:57 +0700 Message-ID: To: tyson andre Cc: php internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] RFC: Add `final class Vector` to PHP From: pierre.php@gmail.com (Pierre Joye) Good morning, Not sure you care or read my reply but I had to jump in one more time here :) On Sat, Sep 18, 2021 at 8:49 AM tyson andre wrote: > setSize is useful in allocating exactly the variable amount of memory needed while using less memory than a PHP array. > `setSize($newSize, 0)` would be much more efficient and concise in initializing the value. > > - Or in quickly reducing the size of the array rather than repeatedly calling pop in a loop. I would rather not reduce it at all, but use the vector_size and keep it. User land set its max size but a realloc/free should not be necessary and counter productive from a perf point of view. If one uses it in a daemon, it can always be destroyed as needed. > > To echo Pierre, a Vector needs to be of a single guaranteed type. > > Yes, this gets us back to the generics conversation again, but I presume (perhaps naively?) there are ways to address this question without getting into full-blown generics. > > Yep, as you said, this type is mixed, just like the SplFixedArray, ArrayObject, values of SplObjectStorage/WeakMap, etc. > Generic support is something that's been brought up before, investigated, then abandoned. > > My concerns with adding StringVector, MixedVector, IntVector, FloatVector, BoolVector, ArrayVector (confusing), ObjectVector, etc is that > > - I doubt many people would agree that there's a wide use case for any > specific one of them compared to a vector of any type. I am lost here. This is the main usage of Vector. For linear arithmetic like dot product, masking, add/sub/mul/div of vector etc. I do not see any other usage per see for all the things I have implemented or saw out there. Additionally, f.e., a string is a vector already on its own, I am not sure a vector of vectors makes sense ;). > This would be even harder to argue for than just a single Vector type. > - Mixes of null and type `T` might make sense in many cases (e.g. optional objects, statistics that failed to get computed, etc) but would be forbidden by that > - It would be a bad choice if generic support did get added in the future. These are special cases for general purposes of vectors. Implementing vectors focusing on these special cases rather than the general purpose (vectorization) would be a strategic mistake. I mentioned it before, but please take a look at the numpy's Vector f.e., with python's operator overload, what has been done there is simply amazing, bringing vector processing/arithmetic a huge boost in performance, even with millions of entries (14 to 400x speed boost compared to classic array, even fixed). > > But really, a non-type-guaranteed Vector/List construct is of fairly little use to me in practice, and that's before we even get into the potential performance optimizations for map() and filter() from type guarantees. > > See earlier comments on `vec`/Generics not being actively worked on right now and probably being a far way away from an implementation that would pass a vote. Generics!=Vector. But I hope that's not the way we are heading here :) > As for optimizations, opcache currently doesn't optimize individual global functions (let alone methods), it optimizes opcodes. > Even array_map()/array_filter() aren't optimized, they call callbacks in an ordinary way. > E.g. https://github.com/php/php-src/pull/5588 or https://externals.io/message/109847 regarding ordinary methods. > > Aside: In the long term, I think the opcache core team had a long-term plan of changing the intermediate representation to make these types of optimizations feasible without workarounds like the one I proposed in 5588 You are fully correct here, I see a lack of the engine devs involvement (not complaining, just a state of the affairs :) in such RFC where this kind of feature could greatly benefit PHP. Well planned, this is a huge addition to PHP. It is also why I am convinced that doing it right for Vectors (as a start) and thinking forwards to JIT and ops overloading (internally or userland) to allow smooth and nice vectorization (as some parts use them already internally f.e.) will bring PHP up to speed with the competition. If we don't, we just have something that would be similar to what anyone could do in userland with more flexibility. Best, -- Pierre @pierrejoye | http://www.libgd.org