Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113435 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 72112 invoked from network); 10 Mar 2021 16:12:24 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 10 Mar 2021 16:12:24 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 982F31804E2 for ; Wed, 10 Mar 2021 08:04:38 -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=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mercury.negativeion.net (mercury.negativeion.net [199.38.81.6]) by php-smtp4.php.net (Postfix) with ESMTP for ; Wed, 10 Mar 2021 08:04:37 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by mercury.negativeion.net (Postfix) with ESMTP id BA3BC20CBE8E9C for ; Wed, 10 Mar 2021 11:04:37 -0500 (EST) Received: from mercury.negativeion.net ([127.0.0.1]) by localhost (mercury.negativeion.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id il-3LukdIhFq for ; Wed, 10 Mar 2021 11:04:36 -0500 (EST) Received: from [10.0.1.102] (unknown [173.225.146.47]) by mercury.negativeion.net (Postfix) with ESMTPSA id CEFBC20CBE8E90 for ; Wed, 10 Mar 2021 11:04:36 -0500 (EST) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.4\)) Date: Wed, 10 Mar 2021 10:04:29 -0600 References: <8812EE70-4720-4639-926E-1EA206624BC1@trowski.com> To: php internals In-Reply-To: Message-ID: X-Mailer: Apple Mail (2.3608.120.23.2.4) Subject: Re: [PHP-DEV] [VOTE] Fibers From: aaron@trowski.com (Aaron Piotrowski) > On Mar 10, 2021, at 4:56 AM, Peter Stalman wrote: >=20 > On Tue, Mar 9, 2021 at 6:03 PM twosee wrote: >=20 > 5. Not compatible with Swoole >=20 > In my opinion, Swoole is an important part of the PHP ecosystem. But = now, Fiber cannot work with Swoole. And based on the above reasons, = Swoole will not consider compatible fiber. >=20 > We would expect some ZendAPI rather than Fiber extensions to provide = support for coroutine switching. >=20 >=20 > Hi Twosee, >=20 > Are you saying that by adding this Fiber code to core it will prevent = Swoole from functioning? If so, that is concerning. Or are you simply = saying that Swoole doesn't like this implementation and will not use it = with their own code? >=20 > One thing to consider when comparing the Fiber implementation is that = the vast majority of PHP applications are still run behind a web server = in short-lived requests. Unlike Swoole, Swow, and Parallel, it isn't = limited to ZTS or CLI. It might not be the ideal solution, but IMO it = is a step in the right direction for PHP to allow for better async = support. >=20 > And I think you are right that "Fiber is just an enhancement of = Generator'', but so what? The Generator addition in 5.5 opened up PHP = to a hacky way of doing async, but it worked everywhere. Fiber allows = that to be much more convenient in switching contexts deep inside a call = stack. I don't think it needs to be the end-all-be-all coroutine = solution to rival Goroutines, and I'm pretty sure it's not trying to be. >=20 > Thanks, > Peter >=20 Hello, This Fiber implementation does not conflict with Swoole. Both could = coexist. However, Swoole's implementation does provide some other = features that this does not, so I believe Twosee was simply saying that = Swoole cannot directly use this fiber implementation. My focus was to = provide a minimalistic implementation in core so user space code can = make other API decisions as they saw fit. Regarding some of the other concerns raised: - Switch notification: The observer notification is triggered before = switching to a fiber and after suspending from a fiber. The timing here = was an open question I've discussed with others and we planned to = examine it later. Moving the second notification before suspending the = second fiber was already being considered. As this was an internal API I = felt it was not needed directly in the RFC. - Fiber is final, as is Generator. I believe it is better to compose = classes rather than extend them. Of course it is always possible to = remove final. - Using Fiber::resume() and Fiber::suspend() models fibers as a stack = and simplifies logic of resuming/suspending fibers. Ruby fibers share = this exact API, though their API uses the term yield instead of suspend. - State functions: Separate methods (i.e., isRunning, isTerminated) = returning a boolean are preferable IMO to comparing integer constants to = a value returned by a status method. This is really a matter of opinion = than one being strictly better than the other. - Pure C coroutine: The extension code provides user space fibers. = Adding functions to create fiber C-only fibers can certainly be done if = the need arises. - Being marked experimental: I was hoping this would be a good = compromise between allowing people to experiment with fibers and = providing the ability to make minor BC breaks if the need arose. I = realize this is generally not the PHP way, however this is, IMO, not = entirely without precedent. JIT and FFI were not widely used before = being added to PHP. Thanks for the feedback! Aaron Piotrowski