Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112969 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 85897 invoked from network); 23 Jan 2021 19:30:46 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 23 Jan 2021 19:30:46 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B6EC51804D1 for ; Sat, 23 Jan 2021 11:11:32 -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=-0.0 required=5.0 tests=BAYES_20,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 ; Sat, 23 Jan 2021 11:11:32 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by mercury.negativeion.net (Postfix) with ESMTP id 72C3F20C291F44; Sat, 23 Jan 2021 14:11:31 -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 dlBzJjbrcrIW; Sat, 23 Jan 2021 14:11:30 -0500 (EST) Received: from [10.0.1.101] (unknown [173.225.146.47]) by mercury.negativeion.net (Postfix) with ESMTPSA id 8B69420C291F37; Sat, 23 Jan 2021 14:11:30 -0500 (EST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.1\)) In-Reply-To: Date: Sat, 23 Jan 2021 13:11:29 -0600 Cc: php internals Content-Transfer-Encoding: quoted-printable Message-ID: <9BF046F2-4799-4CCD-A7F0-739A91C77E83@trowski.com> References: To: Benjamin Eberlei X-Mailer: Apple Mail (2.3608.120.23.2.1) Subject: Re: [PHP-DEV] [RFC] Fibers From: aaron@trowski.com (Aaron Piotrowski) > On Jan 18, 2021, at 8:59 AM, Benjamin Eberlei = wrote: >=20 > Hi Aaron, >=20 > this is a very interesting and welcome piece of functionality. I have = gone > through the RFC a few times now, it have never thought about or worked = with > fibers before, additional feedback will be forthcoming once I grasp = the > details more. >=20 > =46rom my POV the effects on other extensions are the most important = factor, > you already have a section with that for Xdebug, Parallel, and pcov. = But > how does this affect Profilers that manage their own stack of frames, > either all function calls or specifically selected ones. I.e. xhprof, > tideways, datadog, newrelic and so on. Hi Benjamin, Sorry for the bit of a delay in replying. I=E2=80=99ve been busy the = last few days. Profilers that manage their own stack of frames will have to be modified = to account for fibers. The extension currently provides an API to access = the current fiber and uniquely identify each different fiber. The internal API for this will need further discussion amongst the rest = of the internals contributors and hopefully the authors of those = extensions. I omitted any API for this from the RFC as it does not = affect user code. >=20 > At the moment any PHP Profiler only has to manage a single stack of = "open > frames". With Fibers for each fiber a new stack must be opened. >=20 > Does an extension know what the "active" fiber is so that from a > zend_execute_data I know on which stack of open frames I need to push = a new > frame? Four functions are currently provided for determining the current = executing fiber. ``` zend_fiber *zend_get_root_fiber() zend_fiber *zend_get_current_fiber() zend_long zend_fiber_get_id(zend_fiber *fiber) zend_long zend_fiber_get_current_id() ``` These allow you to get the root and current fiber as well as the ID = associated with the fiber. The fiber ID is unique to the process and is never reused, so it can be = used to determine which open stack frame to push a frame. >=20 > Could you add a section to the RFC explaining how a switch between = fibers > works in terms of "the next" and "previous" zend_execute_data that is = run? > This would also be interesting to understand how stack traces work, = for > example debug_print_backtrace. >=20 I added a brief section under FAQs entitled "How are execution stacks = swapped?=E2=80=9D, = https://wiki.php.net/rfc/fibers#how_are_execution_stacks_swapped Backtraces are currently limited to including only the currently = executing fiber. It may be possible to include backtraces of fibers = further down the execution stack, but I had issues when trying to = implement this in the extension during shutdown due to stacks being = freed. Something I think can be addressed if adding to core with the = help of someone more familiar with how references to these stacks are = kept and what should be modified in the functions generating backtraces. Cheers, Aaron Piotrowski