Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125079 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 025961A00BD for ; Wed, 21 Aug 2024 00:18:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1724199648; bh=ZuYM3nDh92+pNi0RAQJn9et6UbzJccL/Pah4e7MS5eE=; h=Date:From:To:Cc:In-Reply-To:References:Subject:From; b=GbiCHO/H2BwkBPJVDwdmy/EsTtDtb3Psx/Fbru2Vco9goyMab1SwW8yTVNTvBJl5+ hHJnuShIZJca+vk6NdIzfiwF7s22qvh+/z9Ibjm4VFTPWxqCvlDchMglHbNLyi24bS mXgoX8HiJbv/6KEboMsO9sPvMO4SJJMsygifeiMc2JqjH/NA0Zyf4Lk5bIRzfNmRq/ 4bxCtADZN/2BEz1tBn79qppR3F6gHGdJffZYZPv2F41diDpHznoGRFOEV/d08nI8/u BjsGG9HFNCMWzhSaKF/fhQVF1kk1aG9/J3GYouhliBGrOUYfRTUPrrbr5AP00wBMh4 UJ2PWH4/eGm6g== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id EDBA6180055 for ; Wed, 21 Aug 2024 00:20:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fhigh6-smtp.messagingengine.com (fhigh6-smtp.messagingengine.com [103.168.172.157]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 21 Aug 2024 00:20:46 +0000 (UTC) Received: from phl-compute-02.internal (phl-compute-02.nyi.internal [10.202.2.42]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 7AF2F1151ABF; Tue, 20 Aug 2024 20:18:56 -0400 (EDT) Received: from phl-imap-09 ([10.202.2.99]) by phl-compute-02.internal (MEProxy); Tue, 20 Aug 2024 20:18:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=cc:cc:content-type:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm2; t=1724199536; x= 1724285936; bh=CJ60U4OO9S+ptqzi/FYPYkPrUkVXLnYO/vSpcfKBjxg=; b=b PPDAIB8h9MWytxjUEvKk7gYsoLCvtV9muWNgSceafs/2RF/NZLAtY97XBfTIkh+C ss5NTIuR0BZNMaHoGZwmcHGNlwvFi02Qg9aMAhtSYGmECiRKKjpcfyhuXhwuR1Dp IINgr2KRx9PchgzGIWmLRgfvKWe8oDpAo8eo6pWYXTIQdXwMnTBPtk3zCeRkW5W6 EQZFxSb7yM45IwX5IQMdee6qi+KYnO71J82gOMqeT+hNcvMVY0ITGr0iEn33QxaU Bvkhr8hU6oL3e/AJ/FpBDqYVfKi9l32aJAScj2aY5be/N3/C7ATiUw3P+zW+B0yN ZxG/zWoZOXPIzX8n1bXsg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1724199536; x=1724285936; bh=CJ60U4OO9S+ptqzi/FYPYkPrUkVX LnYO/vSpcfKBjxg=; b=EFzvNAOpMUcGAi76O4Dns4HkTmQMStFtLuyg/vIxbVmw 86q32gQznh7aHqvkhh8qlAYHe6+3LYsNWmgd3V6Aoi8L28QyWyfs0jkukmY/KWJx QhOujAfumCcNWQGYZm/X2YfiVUMOz+Lx1teDJnQ5l42igquTK3Ce5nQow7wdiAm0 RdNbxtOLan+iZYI8byBKPAwNAmMXbgGaGew44fZVycjbc+vO1oPe/LanT+kqupuu l7xzGmbI19Y99f88jM1vtczb4k0iDZ1ce1jdtw6zC1QYdh+FNIPgsG7z885f9GX2 YHFw5Gb4208KM/yQFTsegHFR0GpaCBl3ugjVhbG2Rw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddujedgfedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepofggfffhvfevkfgjfhfutgesrgdtreerredtjeen ucfhrhhomhepfdftohgsucfnrghnuggvrhhsfdcuoehrohgssegsohhtthhlvggurdgtoh guvghsqeenucggtffrrghtthgvrhhnpeeiueethedvvdefjefhgfeiheelheehtdfhfeek jefflefgvedvkeduteejjedttdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmh epmhgrihhlfhhrohhmpehrohgssegsohhtthhlvggurdgtohguvghspdhnsggprhgtphht thhopedvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehmfigvihgvrhhophhhih hnnhgvhiesghhmrghilhdrtghomhdprhgtphhtthhopehinhhtvghrnhgrlhhssehlihhs thhsrdhphhhprdhnvght X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 2232615A005E; Tue, 20 Aug 2024 20:18:56 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Date: Wed, 21 Aug 2024 02:18:17 +0200 To: "Matthew Weier O'Phinney" Cc: "PHP Developers Mailing List" Message-ID: In-Reply-To: References: <2716f729-4008-4f75-8412-861d8960b746@app.fastmail.com> <26338153-6d16-456a-81bf-8231bdaf1b79@app.fastmail.com> <6197f6e1-d123-41e1-87c8-887c6508bfa2@rwec.co.uk> <97d993ee-c558-43a1-a36a-8e06aa2d829a@app.fastmail.com> <1E9FCFA6-4FAD-4F47-9FC6-6AA8F2FD6BBF@rwec.co.uk> <00ee5318-329c-4a85-a2cd-1fc7050103ba@app.fastmail.com> Subject: Re: [PHP-DEV] function autoloading v4 RFC Content-Type: multipart/alternative; boundary=1897cf3b55b6482bbd5ca8b957d04391 From: rob@bottled.codes ("Rob Landers") --1897cf3b55b6482bbd5ca8b957d04391 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Wed, Aug 21, 2024, at 01:53, Matthew Weier O'Phinney wrote: >=20 >=20 > On Tue, Aug 20, 2024, 4:56=E2=80=AFPM Rob Landers = wrote: >> __ >>=20 >>=20 >> On Tue, Aug 20, 2024, at 18:07, Rob Landers wrote: >>> On Tue, Aug 20, 2024, at 08:50, Rowan Tommins [IMSoP] wrote: >>>>=20 >>>>=20 >>>> On 20 August 2024 00:21:22 BST, Rob Landers wro= te: >>>> > >>>> >I assume you are worried about something like this passing test? >>>> > >>>> >--TEST-- >>>> >show called only once >>>> >--FILE-- >>>> >>>> > >>>> >namespace test; >>>> > >>>> >spl_autoload_register(function($name) { >>>> > echo "name=3D$name\n"; >>>> >}, true, false, SPL_AUTOLOAD_FUNCTION); >>>> > >>>> >echo strlen('foo'); >>>> >echo strlen('bar'); >>>> >echo strlen('baz'); >>>> >?> >>>> >--EXPECT-- >>>> >name=3Dtest\strlen >>>> >333 >>>> > >>>> >In my RFC, I mention it is called exactly once. >>>>=20 >>>>=20 >>>> I haven't looked at the PR, only the RFC, and I did not see this ve= ry important detail explained anywhere. The only thing I can see is this= rather ambiguous sentence: >>>>=20 >>>> > The function autoloader will not be called again.=20 >>>>=20 >>>> That could mean not called again for the current call (compared wit= h proposals that call it a second time with the unequalled name); it cou= ld mean not called again for the current line of code (based on the curr= ent caching behaviour); or never called again for that combination of na= mespace and name; or possibly, never called again for that combination o= f namespace, name, and callback function. >>>>=20 >>>> That's not a small detail of the implementation, it's a really fund= amental difference from previous proposals.=20 >>>>=20 >>>> So I would like to repeat my first response to your RFC: that it sh= ould sound more time explaining your approach to the multiple lookup pro= blem. >>>>=20 >>>> Regards, >>>> Rowan Tommins >>>> [IMSoP] >>>>=20 >>>=20 >>> Thanks Rowan, >>>=20 >>> That's a fair critique. >>>=20 >>> I expect some of the wording will be more clear once I write out the= documentation -- even if it isn't used directly, I tend to write out do= cumentation to force myself to reconcile the code with the plan, find lo= gic bugs, perform larger scale tests, and create tests to verify asserti= ons in the documentation. From there, I'll update the plan or code to ge= t everything to match and spend some time on clarity. It's the hardest p= art, IMHO, as it requires diligently ensuring everything is correct. In = other words, writing the documentation makes it feel like a "real thing"= and it triggers what small amount of perfectionism I have. >>>=20 >>> =E2=80=94 Rob >>=20 >> I have an experimental library that I use for testing these kinds of = things. There are aspects of it that I could work with to make use of fu= nction autoloading. Thus, I did so and benchmarked the performance of un= it tests. The unit testing library makes a ton of "unqualified function = calls". >>=20 >> I spent some time working on two autoloaders: >> 1. A naive autoloader: parses out the file to load, checks if it exi= sts, and then requires the file. >> 2. An optimized autoloader: only cares about the namespace it has re= gistered. All others are an instant return. >=20 > Not to sound flippant, but you do realize that composer does a lot of = optimizations just like this, right? >=20 > PSR-4 exists in large part due to a realization that better optimizati= ons were possible when you mapped namespaces to source code directories.= And Composer takes it a step further when you have it create an optimiz= ed loader, because then it maps classes directly to the files that provi= de them, preventing I/O up to the point that a require is performed.=20 >=20 > My point is that this is why folks have been suggesting that this is a= solved problem. Globally qualify functions, and you get immediate perfo= rmance benefits due to removal of the need to look up via the namespace = first. Most CS tools will even add the imports or qualifiers for you, an= d you can have your IDE or editor configured to do it as well.=20 >=20 >=20 > I wouldn't spend your time on this facet. There are people worried about the performance issues with adding functi= on autoloading (due to having to look up functions at every call, for un= qualified global). And yes, Composer does this for classes, but it doesn= 't (yet) do it for functions, meaning it has to be done manually. So, my= goal here is to either (1), convince people it is a non-issue, or (2) s= how that it is an issue and we should take steps to fix it (such as flip= ping the order functions are looked up, or whatever). Now ... on to WordPress! WordPress makes very few unqualified function calls; however, it can ben= efit from function autoloading since it uses a number of functions files= and such. I had to patch it for this, remove all the require's and gene= rate a function map for the autoloader. I ran three tests: 1. Vanilla WordPress with no changes 2. Vanilla WordPress with no changes, but an autoloader that just retur= ned 3. Modified WordPress to take full advantage of function autoloading Graphs are coming in the RFC, but it looks like WordPress would gain a 1= -3% speed improvement if they used function autoloading. If anyone knows= of any other function-heavy projects, I'd love to throw them at this as= well. Tomorrow I want to take a look at some of the projects Ilija look= ed into that use a number of unqualified functions and see if they will = take a major performance hit by having function autoloading enabled. =E2=80=94 Rob --1897cf3b55b6482bbd5ca8b957d04391 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable

=
On Wed, Aug 21, 2024, at 01:53, Matthew Weier O'Phinney w= rote:


=
On Tue, Aug 20, 2024, 4:56=E2=80= =AFPM Rob Landers <rob@bottled.codes> wrote:
=


On Tue, Aug 20, 2024, = at 18:07, Rob Landers wrote:
On Tue, Aug 20, 2024, at 08:50, Rowan Tom= mins [IMSoP] wrote:


On 20 August 2024= 00:21:22 BST, Rob Landers <rob@bottled.codes> wrote:
>
>I assume you are worried about something = like this passing test?
>
>--TEST--
>show called only once
>--FILE--
><?php
>
>namespace test;=
>
>spl_autoload_register(function($na= me) {
>    echo "name=3D$name\n";
>}, true, false, SPL_AUTOLOAD_FUNCTION);
>
>echo strlen('foo');
>echo strlen('bar'= );
>echo strlen('baz');
>?>
>--EXPECT--
>name=3Dtest\strlen
>333
>
>In my RFC, I mention it is= called exactly once.


I have= n't looked at the PR, only the RFC, and I did not see this very importan= t detail explained anywhere. The only thing I can see is this rather amb= iguous sentence:

>  The function au= toloader will not be called again. 

Th= at could mean not called again for the current call (compared with propo= sals that call it a second time with the unequalled name); it could mean= not called again for the current line of code (based on the current cac= hing behaviour); or never called again for that combination of namespace= and name; or possibly, never called again for that combination of names= pace, name, and callback function.

That's n= ot a small detail of the implementation, it's a really fundamental diffe= rence from previous proposals. 

So I w= ould like to repeat my first response to your RFC: that it should sound = more time explaining your approach to the multiple lookup problem.

Regards,
Rowan Tommins
[IMSoP]


Than= ks Rowan,

That's a fair critique.
=

I expect some of the wording will be more clear once= I write out the documentation -- even if it isn't used directly, I tend= to write out documentation to force myself to reconcile the code with t= he plan, find logic bugs, perform larger scale tests, and create tests t= o verify assertions in the documentation. From there, I'll update the pl= an or code to get everything to match and spend some time on clarity. It= 's the hardest part, IMHO, as it requires diligently ensuring everything= is correct. In other words, writing the documentation makes it feel lik= e a "real thing" and it triggers what small amount of perfectionism I ha= ve.

=E2=80=94 Rob

I have a= n experimental library that I use for testing these kinds of things. The= re are aspects of it that I could work with to make use of function auto= loading. Thus, I did so and benchmarked the performance of unit tests. T= he unit testing library makes a ton of "unqualified function calls".
=

I spent some time working on two autoloaders:<= br>
  1. A naive autoloader: parses out the file to load, checks= if it exists, and then requires the file.
  2. An optimized auto= loader: only cares about the namespace it has registered. All others are= an instant return.

Not to sound flippant, but you do = realize that composer does a lot of optimizations just like this, right?=

PSR-4 exists in = large part due to a realization that better optimizations were possible = when you mapped namespaces to source code directories. And Composer take= s it a step further when you have it create an optimized loader, because= then it maps classes directly to the files that provide them, preventin= g I/O up to the point that a require is performed. 

My point is that this is why fol= ks have been suggesting that this is a solved problem. Globally qualify = functions, and you get immediate performance benefits due to removal of = the need to look up via the namespace first. Most CS tools will even add= the imports or qualifiers for you, and you can have your IDE or editor = configured to do it as well. 

=

I wouldn't spend your time= on this facet.

There ar= e people worried about the performance issues with adding function autol= oading (due to having to look up functions at every call, for unqualifie= d global). And yes, Composer does this for classes, but it doesn't (yet)= do it for functions, meaning it has to be done manually. So, my goal he= re is to either (1), convince people it is a non-issue, or (2) show that= it is an issue and we should take steps to fix it (such as flipping the= order functions are looked up, or whatever).

Now ... on to WordPress!

WordPress makes= very few unqualified function calls; however, it can benefit from funct= ion autoloading since it uses a number of functions files and such. I ha= d to patch it for this, remove all the require's and generate a function= map for the autoloader. I ran three tests:
  1. Vanilla Wor= dPress with no changes
  2. Vanilla WordPress with no changes, bu= t an autoloader that just returned
  3. Modified WordPress to tak= e full advantage of function autoloading
Graphs are co= ming in the RFC, but it looks like WordPress would gain a 1-3% speed imp= rovement if they used function autoloading. If anyone knows of any other= function-heavy projects, I'd love to throw them at this as well. Tomorr= ow I want to take a look at some of the projects Ilija looked into = that use a number of unqualified functions and see if they will take a m= ajor performance hit by having function autoloading enabled.

=E2=80=94 Rob
--1897cf3b55b6482bbd5ca8b957d04391--