Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126571 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 E69EE1A00BC for ; Tue, 4 Mar 2025 23:09:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1741129610; bh=5R0rwcebWyqVdvkE+rWDiWUIBvwXTlaVt43RC37Glu4=; h=Date:From:To:Cc:In-Reply-To:References:Subject:From; b=ChIqhYm33/hJsDJtPsOzbnLkfBvn9zrIqcKMHETiGRBYETsUsKv8tK2CfYOC2s/UN IEpRoe1FZyIbqSi7CoozESn46LP4NlZ3PDZOUPyWlEuyBZRJ3uG6ZXGjv1woFwRIJJ I4plX3NNRX2gZa3SyQpg/O3TCCzwk4BF/ZxQTmkb6Fum82kouMAispB+5eVBMx0ia4 m3pAKUL5x546/Q71rzQdsYs3dUTKktCvbJHxntZjVfkCFqmR1e/06yoA8mAmaUuE/D rWF7KU9A5PA6WBCizCoOby3XYFLUjrXfimPS0xD4S2Jzl2OiLwaw9tGlJMnSfHLndk no4Acu+jxk1DQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5C0CD18007E for ; Tue, 4 Mar 2025 23:06:49 +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=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fhigh-a3-smtp.messagingengine.com (fhigh-a3-smtp.messagingengine.com [103.168.172.154]) (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 ; Tue, 4 Mar 2025 23:06:48 +0000 (UTC) Received: from phl-compute-12.internal (phl-compute-12.phl.internal [10.202.2.52]) by mailfhigh.phl.internal (Postfix) with ESMTP id 8A7B1114022B; Tue, 4 Mar 2025 18:09:24 -0500 (EST) Received: from phl-imap-09 ([10.202.2.99]) by phl-compute-12.internal (MEProxy); Tue, 04 Mar 2025 18:09:24 -0500 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=1741129764; x= 1741216164; bh=VUv2fGRoquGEQ3DG1gQ8lhu6zc+FyFPgJFdnZQNlcSU=; b=O +81rZc6lPE5P8TIK0+O+aPB8g2K8Ju8bdJz563LPtdl0urrLhKJ8jPv8kaE9weiW SrYHpnALpWGegcunRsm5+hJSiHI22TJkGXywQ/VadiOpYaufFCcIASp4JTMhoH3a pIXIRkT681kDEVAPX15oL9Px3+2jIvwZg4jramtNOdPPU4dyBAR4KLpSIhtWqqRU t0zEj3i8QkEearrbOED1LXd9v193AzW1oaW06uvC/yjSBQblxaEzLaiWblJOtfwP BRh9nfZVnptnIm5PAf+yL9Sf3nGSqDr1MFzZnhkUBmKilhkVgDiCux0PpEbcjwsh OLVJYVeREGfCw60PJ8S7g== 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-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1741129764; x=1741216164; bh=VUv2fGRoquGEQ3DG1gQ8lhu6zc+FyFPgJFd nZQNlcSU=; b=WH2+gnwOSjnjHTQROK/8T3bzEVRGZFbJTvS+G9rKcVvtFxmwaBU 510NOkxo1Ml3QXWZkkVEz7T17NVG7Jousvr990BFkx2lCXMybA2ToSGidgRbkQlN aa9+xqubipDjnNtoWoE/KkAbmisLrmOFZgr7C1dsNv4mhs1gl8avltY7FC0grHh1 RhYABlD/Y93NWnhn8QpoRBvzr0hgWXiYMZ7hmalHENsmkpNUzj4111Glp9Vrvd9A 2PbckHnUXNF1aaWeTtVZ0C8/PGrEKxPx3SlfLETcjG2kwgY3BgHG3DyVjkM5+p5e dP1njK44FqSt6bLLaJZWv8lG3gGKc8EEjqA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddutdefvdegucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih gvnhhtshculddquddttddmnecujfgurhepofggfffhvfevkfgjfhfutgesrgdtreerredt jeenucfhrhhomhepfdftohgsucfnrghnuggvrhhsfdcuoehrohgssegsohhtthhlvggurd gtohguvghsqeenucggtffrrghtthgvrhhnpeeiueethedvvdefjefhgfeiheelheehtdfh feekjefflefgvedvkeduteejjedttdenucevlhhushhtvghrufhiiigvpedtnecurfgrrh grmhepmhgrihhlfhhrohhmpehrohgssegsohhtthhlvggurdgtohguvghspdhnsggprhgt phhtthhopeefpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehlrghrrhihsehgrg hrfhhivghlughtvggthhdrtghomhdprhgtphhtthhopeiishhiuggvlhhnihhksehgmhgr ihhlrdgtohhmpdhrtghpthhtohepihhnthgvrhhnrghlsheslhhishhtshdrphhhphdrnh gvth X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 16514780068; Tue, 4 Mar 2025 18:09:24 -0500 (EST) 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, 05 Mar 2025 00:09:03 +0100 To: "Eugene Sidelnyk" , "Larry Garfield" Cc: "php internals" Message-ID: <35053d61-333e-4006-b806-768001e44d7e@app.fastmail.com> In-Reply-To: References: <9964db8c-0ffe-43d5-8246-47fc76b07180@app.fastmail.com> Subject: Re: [PHP-DEV] PHP True Async RFC Content-Type: multipart/alternative; boundary=b68f61bffe874a669fc62479d4815bec From: rob@bottled.codes ("Rob Landers") --b68f61bffe874a669fc62479d4815bec Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Tue, Mar 4, 2025, at 23:54, Eugene Sidelnyk wrote: > Hi there, >=20 > I would also like to highlight some interesting ideas that I find bein= g useful to consider. >=20 > Recently Bend programming language has been released, and it incorpora= tes a completely different view on the conception of "code", in the defi= nition of "what it is" and "how it should be interpreted". >=20 > While we interpret it as a sequence of instructions, the proper way of= seeing it is the graph of instructions. On every step we reduce that gr= aph, by running the code of the nodes current node depends on.=20 >=20 > Therefore, basically everything could paralleled w/o the need to have = fancy management of threads and other low-level things. >=20 > For example, having this code: >=20 > $foo =3D foo(); > $bar =3D bar(); > $baz =3D $foo + $bar; >=20 > If it was run in Bend, it would be interpreted so that foo() and bar()= functions are executed in parallel, and $baz =3D $foo + $bar is execute= d afterwards, since this computation depends on the other two. >=20 > The key, most excellently beautiful feature=20 > here is that all async management is under the hood, exposing nothing = for the developers to be bothered with. >=20 > That being said, I also want to mention that Bend has a primitive for = concurrent loops. Actually, they used another solution, different from l= oops, since loops are sequential by their essense (iterative one by one)= . They introduced a concurrent alternative for loops with "bend" keyword= , allowing data structures to be traversed in parallel. >=20 > I think this is actually "the right way" of doing parallel processing = in general and async programming in particular, and this is greatly to b= e considered for having at least some principles applied in PHP. >=20 > What I think it could be. >=20 > async function baz(): int { > $foo =3D foo(); > $bar =3D bar(); >=20 > return $foo + $bar; > } >=20 > // value is returned just like from any other ordinary function > $val =3D baz();=20 >=20 > Function above could run foo() in one fiber, and bar() in another, bot= h of them being awaited at the return statement (at the first statement = where the value is actually used / referenced, if we put it more general= ly) so that actual values could be taken. >=20 > In other words, async function is not promise-based as in other langua= ges that suffer from red blue function problem, but rather it is functio= n with coroutine flow of execution, so that foo() is executed as the fir= st coroutine, and when it blocks, then bar() is executed until it also b= locks. Then, at plus operator being evaluated, $foo is awaited, and $bar= is awaited, since they are necessary parts for + operation to complete. >=20 >=20 > Best regards Huh. Reminds me of SSA, which can identify independent computations like= that. It=E2=80=99s used by go, and many other compiled languages, but n= ot in the same way this bend language does it. So, that=E2=80=99s intere= sting. I don=E2=80=99t know if php could implement SSA (maybe opcache could), b= ut with how dynamic php is, I=E2=80=99m not sure it would be helpful. An interesting application nonetheless, thanks for sharing! =E2=80=94 Rob --b68f61bffe874a669fc62479d4815bec Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable

=
On Tue, Mar 4, 2025, at 23:54, Eugene Sidelnyk wrote:
=
<= div dir=3D"auto">Hi there,

I w= ould also like to highlight some interesting ideas that I find being use= ful to consider.

= Recently Bend programming language has been released, and it incorporate= s a completely different view on the conception of "code", in the defini= tion of "what it is" and "how it should be interpreted".

While we interpret it as a seque= nce of instructions, the proper way of seeing it is the graph of instruc= tions. On every step we reduce that graph, by running the code of the no= des current node depends on. 

=
Therefore, basically everything could paralleled w/o t= he need to have fancy management of threads and other low-level things.<= br>

For example, havi= ng this code:

$fo= o =3D foo();
$bar =3D bar();
$baz =3D $foo + $bar;

If it was run in Bend, it would be interpreted so that f= oo() and bar() functions are executed in parallel, and $baz =3D $foo + $= bar is executed afterwards, since this computation depends on the o= ther two.

The key= , most excellently beautiful feature 
he= re is that all async management is under the hood, exposing nothing for = the developers to be bothered with.

That being said, I also want to mention that Bend has= a primitive for concurrent loops. Actually, they used another solution,= different from loops, since loops are sequential by their essense (iter= ative one by one). They introduced a concurrent alternative for loops wi= th "bend" keyword, allowing data structures to be traversed in parallel.=

I think this is = actually "the right way" of doing parallel processing in general and asy= nc programming in particular, and this is greatly to be considered for h= aving at least some principles applied in PHP.

What I think it could be.

async function baz(): int {
  $foo =3D foo();
=   $bar =3D bar();

  return $foo + $bar;
}
<= div dir=3D"auto">
// value is returned just l= ike from any other ordinary function
$val =3D= baz(); 

Fun= ction above could run foo() in one fiber, and bar() in another, both of = them being awaited at the return statement (at the first statement where= the value is actually used / referenced, if we put it more generally) s= o that actual values could be taken.

In other words, async function is not promise-based = as in other languages that suffer from red blue function problem, but ra= ther it is function with coroutine flow of execution, so that foo() is e= xecuted as the first coroutine, and when it blocks, then bar() is execut= ed until it also blocks. Then, at plus operator being evaluated, $foo is= awaited, and $bar is awaited, since they are necessary parts for + oper= ation to complete.


Best regards
<= div>
Huh. Reminds me of SSA, which can identify independen= t computations like that. It=E2=80=99s used by go, and many other compil= ed languages, but not in the same way this bend language does it. So, th= at=E2=80=99s interesting.

I don=E2=80=99t k= now if php could implement SSA (maybe opcache could), but with how dynam= ic php is, I=E2=80=99m not sure it would be helpful.

<= /div>
An interesting application nonetheless, thanks for sharing!

=E2=80=94 Rob
--b68f61bffe874a669fc62479d4815bec--