Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113579 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 3047 invoked from network); 16 Mar 2021 21:04:07 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 16 Mar 2021 21:04:07 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 533041804B8 for ; Tue, 16 Mar 2021 13:57:57 -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-Virus: No X-Envelope-From: Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (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 ; Tue, 16 Mar 2021 13:57:56 -0700 (PDT) Received: by mail-pl1-f178.google.com with SMTP id o10so5341602plg.11 for ; Tue, 16 Mar 2021 13:57:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=nWCwMHvhjV08lnmpVNkGK07Hy1Whto3Y5A56udNb3pg=; b=mo5KpmvJFuDrAxu1RSoO+myTA0DrGZnX4TFwojCA3ZfOHzF/sQpewu8ey4n/BElOsj ouQcmVXOobDkE59vxOAxN06TyAnoNRj1gg6GCwJ7DEHpsVFRc5gkTXEoq+ZHIYuuZkWV /z2udNMo2fMjZT8A+ZS/3T0nJVL+NAhkr4pDP5satL5wLGzWh/Tgc7xTM2rvlNoKdQpg mUqOfciO9YIr8d5Bme6t7Q7LjJJrgigC3te4K8q1/6dFpbzPLYYl7kYhV+s7Iz2h+8ke L6L24fzWZJ8Gq9FzwqvON5wHGZoAhr81Zx2pjOD5IW6chR07JKdRk+16aVzek58VQM60 BBSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=nWCwMHvhjV08lnmpVNkGK07Hy1Whto3Y5A56udNb3pg=; b=i9odn833k8dyaPXV0r9s30ssyACC799uNWCUVXZAUAO2yJuKDPCp9IrZNOUJnzLgqO VyRQZ8VWvjlzFY9wPrdtO53al79w7wBCaPYMVfxnnIxHZ/DZmLxJe4cNQoC58+tx1IEc Bf9JqOLzVUpnlUwqBNwqeRlOHnDVn4yBrCD5YJ86HB/PAuu8jDl7/41JVNZFYBJs4UqM d8Z0LR3HsROji0jDvSz9Q1DPjkqsvJoQJAtvFdY5/z7CFybDWuEtOH6BfvBg2Jm9djm7 A0e4bvSxiiqWF4Y9tfqwjTKfzK4sGmW5sNOVg97fcUlXxc1iiJ8WJZxMmYwpcfvBsipU 4FoQ== X-Gm-Message-State: AOAM531q5YuhGNoVVxXwi8MdE2KDZFU4QM+D90BlgKsLBiF8r0bZmXj0 /9VjjzDRaACO9xpcUovSjnEueSbWt8DBDCfF5+rD5d2n1l6lDD73 X-Google-Smtp-Source: ABdhPJzs/vB5m/ZjdtdTbODPhNztGDRlJDCvUWpiZ7/TCinlISJXjQN0WNgMv5ZPkheJ0IaQiT/NPVThP3uCw8nRFME= X-Received: by 2002:a17:90a:5898:: with SMTP id j24mr860587pji.103.1615928274101; Tue, 16 Mar 2021 13:57:54 -0700 (PDT) MIME-Version: 1.0 References: <70951423-5e77-c150-6dce-dd3c62f8dc8b@php.net> <0b994a60-7970-605b-1657-d6ee732690e5@gmx.de> <5C73A1DE-E563-4F69-B8C7-6506F81D7345@trowski.com> In-Reply-To: Date: Tue, 16 Mar 2021 20:57:43 +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] [VOTE] Fibers From: joshdifabio@gmail.com (Josh Di Fabio) Hi Larry, Thanks for the feedback. Replies inline. On Tue, Mar 16, 2021 at 8:33 PM Larry Garfield wro= te: > > On Tue, Mar 16, 2021, at 1:44 PM, Josh Di Fabio wrote: > > > Perhaps we could rather make fibers *opt in* at the *callsite* > > (similar to goroutine calls) in order to prevent functions > > unexpectedly being executed asynchronously due to faraway changes. > > This would be safe and predictable while also avoiding the "What color > > is your function" problem. For example > > > > private function capturePayment(): void > > { > > $paymentRequest =3D preparePaymentRequest($this->currentOrder); > > // allow, but don't require, the underlying call to use > > fibers. Callers higher up the stack would also have to opt in > > async $this->paymentGateway->capturePayment($paymentRequest); > > > > $this->currentOrder->setTransactionId($paymentRequest->getTransactionId= ()); > > } > > > > With this approach, APIs we'd avoid the "what colour is your function" > > problem without sacrificing the safety that we really need in e.g. > > ecommerce. > > "Callers higher up the stack would also have to opt in" is precisely and = specifically the design flaw that fibers avoid. What you are calling a design flaw, is by far the most common approach to async in other languages. > What you're suggesting is that a given IO call would become magically non= -blocking iff its entire parent call stack was called with `async` keywords= , which could be 50 stack frames easily. Aside from the implementation chal= lenge, and the fact that it would require two different code paths even in = the PHP code around that IO ... This is already the case with the fiber RFC as it stands. If you are not within fiber context, then calls to fiber-enabled are sync. If you are within fiber context, they're async. > ... event if it could be implemented it would mean that basically no IO c= ode would ever run async, ever, because there is one function call somewher= e in the stack that didn't include `async` in some library that everyone us= es but hasn't been updated to prefix every single function call with `async= `. This is very close to how goroutines work in Golang. > That is literally the "What color is your function" problem. Some of the "problems" are still present, but I am still suggesting that there be only one implementation of each function, rather than two, and that implementation can be called from either a synchronous or asynchronous context. > I should also note that if you are following good practices to begin with= , your code base is 90% pure, immutable functions/methods and so entirely s= afe from cooperative multitasking race conditions. Right, but that code should generally be synchronous, because if a function is async then it's doing IO and isn't a pure function. But note that as this RFC stands there's no way to know that without actually reading all the code. Perhaps you are rather talking about side effects, it's unclear. > If that's not the case, you have a buggy codebase already even without fi= bers. Fibers would just make it more obvious. Fibers will not make those issues obvious at all. The issues I'm describing will only crop up spontaneously and under load. > --Larry Garfield > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > Cheers