Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112688 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 14544 invoked from network); 30 Dec 2020 21:52:46 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 30 Dec 2020 21:52:46 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 3EEA11804C6 for ; Wed, 30 Dec 2020 13:27:34 -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-Virus: No X-Envelope-From: Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) (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 ; Wed, 30 Dec 2020 13:27:34 -0800 (PST) Received: by mail-lf1-f54.google.com with SMTP id b26so40386554lff.9 for ; Wed, 30 Dec 2020 13:27:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=DMarG34dAnofzlPTTf+o2cJYPoenA7mLwBq4Y/9Mtd4=; b=VBi02GQwM/xrFEfN62bH3xEqbsnwSww/LPSVZhT+Nw7RWj9abnblSikH8GYobtR5Mu m1kBAq1kK4lxyysBCBEVBdmqlR2wWuopMfisukV30S9bH+J5w/qRQaaI+yPNrqNsULQz kGDHWGAZYjR3W0DNYeorjU0jQH8EDbO5ZLqdg33zbaVt9Ks0Gcl8e+agDi1wzXJM5FcH qJ1o/xUFGH6fm63NAjMP2ynuDNfVp0/F9dMCFfE1isYOZiYrT2U6VBcMgpkpNU+DUiol +RxZDP8bvttF5u8M7y6DnjYjWFJJx3qU3wu2o02tlxDZ3tF774l3hwHPOQO5Q0vr4ebz cHcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=DMarG34dAnofzlPTTf+o2cJYPoenA7mLwBq4Y/9Mtd4=; b=avUS41S1IDBd+Uk1/TDbAhwPY+vxEk26A+8AEX8bfYn3nPE+xmJjLCw+UEQOjOy5e1 d7eoIXYu+3veBlaSoRYjc5E+h+UEd4Qvp95EYfYc09bi5rWLFXBUogv1dBr+viabx9Xr l2x/5l7WdcKjNsOcUYDM9+uTZBr6b9hlHw3Zuq4QTNumaUgTIA1sGkEd6l1Gp830gCc3 887d24YjyT/P6OKVa/5X1qhKeo4Nu0UjD9yqMlkn1tkqXRKkVhXUeodTcWEZcxD5zrNH S30x4P9p9n7plnVK4VN7uu5A5nYJc7qUJjb1qa0Btyxg5aR+FnGqKl790vQHbmKvfsAb pcFw== X-Gm-Message-State: AOAM530iIkQ66jKxQtgEdkfaAdGpVw/ewEghh98mhnDtvbGalwZGKFYr ho8tMH+0EIMoJ/MxPeYR/SpcBVSiYmDWW/hBsp0= X-Google-Smtp-Source: ABdhPJy6+DiQs+YrnCxv8ubjyg/cMCvj/UsAjXeLscKnGE1J76JcUJvE227p8v3WWxkMadTmEzzeArMVz6ZO1U3lln8= X-Received: by 2002:a2e:b610:: with SMTP id r16mr26013939ljn.470.1609363652678; Wed, 30 Dec 2020 13:27:32 -0800 (PST) MIME-Version: 1.0 Received: by 2002:ab3:7110:0:0:0:0:0 with HTTP; Wed, 30 Dec 2020 13:27:31 -0800 (PST) In-Reply-To: <20df5745-f2e0-418c-94c1-46bd7712592a@www.fastmail.com> References: <1d0abb04-4987-43a9-85bc-bccc3bd6be9a@www.fastmail.com> <03108284-740a-4a5d-130f-15b2e67e9df9@mabe.berlin> <459d7ff7-e553-dce9-7d43-c3b1e772e572@gmail.com> <7f4fe9ca-1c20-6f69-cef0-a9718af742a3@gmail.com> <3e683903-66cb-4a1a-9ff8-22887dbb8dce@www.fastmail.com> <20df5745-f2e0-418c-94c1-46bd7712592a@www.fastmail.com> Date: Wed, 30 Dec 2020 21:27:31 +0000 Message-ID: To: Larry Garfield Cc: php internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Analysis of property visibility, immutability, and cloning proposals From: olleharstedt@gmail.com (=?UTF-8?Q?Olle_H=C3=A4rstedt?=) 2020-12-30 20:37 GMT, Larry Garfield : > On Wed, Dec 30, 2020, at 2:16 PM, Olle H=C3=A4rstedt wrote: > >> > Ok. You have a benchmark for this? I can make one otherwise, for the >> > query >> > example. >> > >> > It worries me a little that immutability is pushed into the ecosystem >> > as a >> > silver bullet. Main reason functional languages are using it is becaus= e >> > ownership is a newer concept, so it hasn't been adapted as much. >> >> Tiny benchmark here: >> https://gist.github.com/olleharstedt/eaaf1dd40be541f84aa0f3954a0ea54a >> >> Running this on my ARM machine with PHP 7.2 gives ~1.2s for the >> immutable loop, ~0.35s for the mutable one, meaning immutability is >> ~3x as expensive performance wise. And this is for a SMALL object - I >> suspect the performance hit will grow the bigger the class gets (more >> properties to clone). Correct me if I'm wrong. :/ > > > That's not a valid benchmark; it's comparing cloning and method invocatio= n > against just property sets. The method calls are chewing up most of the > time there. > > Here's a more fair comparison on my laptop: > https://gist.github.com/Crell/848568124e25c8c83fc4da5455063bab > > Which is only ~20% slower. And that's when dealing with very small numbe= rs, > so in most cases you're unlikely to notice a difference unless you really > are iterating over something a million times. > > I also tossed some big string properties into the class, and while the to= tal > time went up a bit the ratio between the two stayed about the same. > > --Larry Garfield Oh yeah. Huh. Didn't realize method calling was expensive. :) Another good reason to not use setters, lol. On my machine it's ~70% slower with "with" now (running multiple runs, using bash "time"). The performance might matter when frameworks start to adapt patterns like this. It's already in PSR, with the HTTP message interface etc. Now I'm curious how OCaml and JS performs with a similar benchmark. Since they both have tracing GC, and PHP uses ref counting...